next.js
next.js copied to clipboard
[Next 15] Preloading multiple modules prevents the `dev` server from running
Link to the code that reproduces this issue
To Reproduce
- Attempt to start the application via
npm run dev. - Running the app will fail.
Current vs. Expected behavior
In Next 15 RC, preloading multiple modules via NODE_MODULES=--require ./module1 --require ./module2 throws an error that prevents the server from running.
- Although I can tell by the logs that the modules are properly preloaded, the server still does not run.
Example:
"scripts": {
"dev": "NODE_OPTIONS='--require ./required-module1 --require ./required-module2' next dev",
}
Current behavior
➜ workspace git:(master) ✗ npm run dev
> dev
> NODE_OPTIONS='--require ./required-module1 --require ./required-module2' next dev
===== module 1
===== module 2
node:internal/modules/cjs/loader:1051
throw err;
^
Error: Cannot find module './required-module1 ./required-module2'
Require stack:
- internal/preload
at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
at Module._load (node:internal/modules/cjs/loader:901:27)
at internalRequire (node:internal/modules/cjs/loader:166:19)
at Module._preloadModules (node:internal/modules/cjs/loader:1420:5)
at loadPreloadModules (node:internal/process/pre_execution:705:5)
at setupUserModules (node:internal/process/pre_execution:170:3)
at prepareExecution (node:internal/process/pre_execution:132:5)
at prepareMainThreadExecution (node:internal/process/pre_execution:55:3)
at node:internal/main/run_main_module:10:1 {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'internal/preload' ]
}
Node.js v20.9.0
Expected behavior
- Next 15 should start.
- For further context, this works in a Next 14 sandbox:
➜ workspace git:(master) ✗ npm run dev
> dev
> NODE_OPTIONS='--require ./required-module1 --require ./required-module2' next dev
===== module 1
===== module 2
===== module 1
===== module 2
▲ Next.js 14.2.4
- Local: http://localhost:3000
✓ Starting...
✓ Ready in 1952ms
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023
Available memory (MB): 4102
Available CPU cores: 2
Binaries:
Node: 20.9.0
npm: 9.8.1
Yarn: 1.22.19
pnpm: 8.10.2
Relevant Packages:
next: 15.0.0-canary.47 // Latest available version is detected (15.0.0-canary.47).
eslint-config-next: N/A
react: 19.0.0-rc-6f23540c7d-20240528
react-dom: 19.0.0-rc-6f23540c7d-20240528
typescript: 5.3.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Runtime
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local)
Additional context
- I could reproduce this behavior all the way back to 15.0.0-canary.0.
- Preloading does work if only include a single module, i.e. only one
--require.