Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building with pnpm workspace on windows will lead to Next dist be deleted on second build #80

Open
clansty opened this issue Oct 9, 2024 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@clansty
Copy link
Contributor

clansty commented Oct 9, 2024

When I execute npm run build:worker for the second time, build will be failed with the following error

> Build error occurred
Error: Cannot find module './impl'
Require stack:
- D:\project-dir\node_modules\.pnpm\[email protected][email protected][email protected][email protected][email protected]\node_modules\next\dist\build\webpack-build\index.js
- D:\project-dir\node_modules\.pnpm\[email protected][email protected][email protected][email protected][email protected]\node_modules\next\dist\build\index.js
- D:\project-dir\node_modules\.pnpm\[email protected][email protected][email protected][email protected][email protected]\node_modules\next\dist\cli\next-build.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1219:15)
    at D:\project-dir\node_modules\.pnpm\[email protected][email protected][email protected][email protected][email protected]\node_modules\next\dist\server\require-hook.js:55:36
    at Module._load (node:internal/modules/cjs/loader:1045:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)
    at Module.require (node:internal/modules/cjs/loader:1304:12)
    at mod.require (D:\project-dir\node_modules\.pnpm\[email protected][email protected][email protected][email protected][email protected]\node_modules\next\dist\server\require-hook.js:65:28)
    at require (node:internal/modules/helpers:123:16)
    at webpackBuild (D:\project-dir\node_modules\.pnpm\[email protected][email protected][email protected][email protected][email protected]\node_modules\next\dist\build\webpack-build\index.js:168:34)
    at D:\project-dir\node_modules\.pnpm\[email protected][email protected][email protected][email protected][email protected]\node_modules\next\dist\build\index.js:1002:148 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\Projects\\AquaDX-Bot\\node_modules\\.pnpm\\[email protected][email protected][email protected][email protected][email protected]\\node_modules\\next\\dist\\build\\webpack-build\\index.js',
    'D:\\Projects\\AquaDX-Bot\\node_modules\\.pnpm\\[email protected][email protected][email protected][email protected][email protected]\\node_modules\\next\\dist\\build\\index.js',
    'D:\\Projects\\AquaDX-Bot\\node_modules\\.pnpm\\[email protected][email protected][email protected][email protected][email protected]\\node_modules\\next\\dist\\cli\\next-build.js'
  ]
}

If I ls D:\project-dir\node_modules\.pnpm\[email protected][email protected][email protected][email protected][email protected]\node_modules\next\ will get an empty dir. It is normal before the second build.

I think it's some file deletion method in Next will recursive delete file in folder symlink, because there's a node_module with symlink produced by pnpm when set NEXT_PRIVATE_STANDALONE: "true"

@vicb vicb added bug Something isn't working help wanted Extra attention is needed labels Oct 9, 2024
@shashankboosi
Copy link
Contributor

shashankboosi commented Oct 11, 2024

Hey @clansty,

I have tried running a sample next.js app from the examples using the adapter with admin rights (pwsh). It works the first time but throws a bunch of errors the second time as shown below.

First time: pnpm --filter api preview:worker
Second time: pnpm --filter api build:worker

image
image

It looks like, most data from node_modules and the .next dir are being removed and the adapter is looking for something that doesn't exist.

I will try and see why but I hope it helps anyone looking into it!

To get it working, I has to delete the node_modules on the root and the api example project and run pnpm i again

@clansty
Copy link
Contributor Author

clansty commented Oct 11, 2024

You can remove the .next/standalone folder with file explorer and then build

I think there's some logic in the original next.js build doing recursive delete and treated symlinked folders like regular folders

@cielorz
Copy link

cielorz commented Oct 12, 2024

Same issue, second build always got failure in my project

@twodft
Copy link

twodft commented Oct 14, 2024

Use pnpm too, In my case, next seems got removed after the first success build,

node:internal/modules/cjs/loader:1228
  throw err;
  ^

Error: Cannot find module 'F:\DEMO\www\node_modules\next\dist\bin\next'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)
    at Module._load (node:internal/modules/cjs/loader:1051:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.18.0
 ELIFECYCLE  Command failed with exit code 1.

remove node_modules and re-install dependencies, then we can build it, but the second build always fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants