#Module not found dist/server.js

10 messages · Page 1 of 1 (latest)

elfin wolf
#

I created a nextjs project, and then added payload to it using this docs
https://payloadcms.com/docs/getting-started/installation

After I made some changes, used some other code, I get this error
Error: Cannot find module 'C:\Users\ursua\Development\nextjs\next-payload\dist\server.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
at Module._load (node:internal/modules/cjs/loader:985:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

I could not find any dist/server.js file on other code

Payload CMS

Payload is a headless CMS and application framework built with TypeScript, Node.js, React and MongoDB

lunar summitBOT
burnt ruin
#

you should run npm run build

elfin wolf
# burnt ruin you should run npm run build
> next-payload@1.0.0 build
> yarn copyfiles && yarn build:payload && yarn build:server

yarn run v1.22.22
$ copyfiles -u 1 "src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}" dist/
Done in 0.42s.
yarn run v1.22.22
$ cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build
Done in 33.55s.
yarn run v1.22.22
$ tsc
Done in 4.01s.

C:\Users\ursua\Development\nextjs\next-payload>npm run dev

> next-payload@1.0.0 dev
> cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon

[nodemon] 2.0.22
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node dist/server.js`
node:internal/modules/cjs/loader:1147
  throw err;
  ^

Error: Cannot find module 'C:\Users\ursua\Development\nextjs\next-payload\dist\server.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.11.0
[nodemon] app crashed - waiting for file changes before starting...``` while the dist folder did generate, the server.js didnt
elfin wolf
#

now I get completely new error that does not make really much sense

^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at loadConfig (C:\Users\ursua\Development\nextjs\next-payload\node_modules\payload\dist\config\load.js:28:27)
    at BasePayload.init (C:\Users\ursua\Development\nextjs\next-payload\node_modules\payload\dist\payload.js:197:33)

Node.js v20.11.0
[nodemon] app crashed - waiting for file changes before starting...```
#

cause the new server.js is the copy of server.ts, which uses these imports

burnt ruin
#

Have you added .env file

#

For payload

elfin wolf
#

database uri and the payload secret

burnt ruin
#

Also the stable node version is 18.18.2 i guess