Hey everyone. I’m trying to deploy my application but nothing seems to work. I’ve tried the example repository and changed the path to ./bin/www/dist/server.js, but that doesn’t seem to work too.
here are my scripts:
"scripts": {
"start": "NODE_ENV=production node ./dist/server.js",
"dev": "nodemon server.js --exec babel-node",
"build": "babel server.js -d dist",
"build:digitalocean": "npm install --production=false && npm run build && npm ci && npm run start"
},
And here are the logs
[2024-03-07 10:24:22]
[2024-03-07 10:24:22] > server@1.0.0 start
[2024-03-07 10:24:22] > NODE_ENV=production node ./dist/server.js
[2024-03-07 10:24:22]
[2024-03-07 10:24:23] node:internal/modules/cjs/loader:1147
[2024-03-07 10:24:23] throw err;
[2024-03-07 10:24:23] ^
[2024-03-07 10:24:23]
[2024-03-07 10:24:23] Error: Cannot find module '/workspace/dist/server.js'
[2024-03-07 10:24:23] at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
[2024-03-07 10:24:23] at Module._load (node:internal/modules/cjs/loader:985:27)
[2024-03-07 10:24:23] at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
[2024-03-07 10:24:23] at node:internal/main/run_main_module:28:49 {
[2024-03-07 10:24:23] code: 'MODULE_NOT_FOUND',
[2024-03-07 10:24:23] requireStack: []
[2024-03-07 10:24:23] }
[2024-03-07 10:24:23]
[2024-03-07 10:24:23] Node.js v20.10.0
[2024-03-07 10:24:16]
[2024-03-07 10:24:16] > server@1.0.0 start
[2024-03-07 10:24:16] > NODE_ENV=production node ./dist/server.js
[2024-03-07 10:24:16]
[2024-03-07 10:24:16] node:internal/modules/cjs/loader:1147
[2024-03-07 10:24:16] throw err;
[2024-03-07 10:24:16] ^
[2024-03-07 10:24:16]
[2024-03-07 10:24:16] Error: Cannot find module '/workspace/dist/server.js'
[2024-03-07 10:24:16] at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
[2024-03-07 10:24:16] at Module._load (node:internal/modules/cjs/loader:985:27)
[2024-03-07 10:24:16] at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
[2024-03-07 10:24:16] at node:internal/main/run_main_module:28:49 {
[2024-03-07 10:24:16] code: 'MODULE_NOT_FOUND',
[2024-03-07 10:24:16] requireStack: []
[2024-03-07 10:24:16] }
[2024-03-07 10:24:16]
[2024-03-07 10:24:16] Node.js v20.10.0
[]
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey!
The error “Cannot find module ‘/workspace/dist/server.js’” indicates that Node.js is unable to locate the
server.js
file in thedist
directory when trying to execute it.This issue is usually related to the build and deployment process not completing as expected. Here are some steps to troubleshoot and potentially resolve the issue:
You need to make sure that the
build
script in yourpackage.json
correctly compiles your source code to thedist
directory. The script"build": "babel server.js -d dist"
should generate theserver.js
file in thedist
folder.Before deploying, locally run your
build
script and check ifserver.js
is successfully generated in thedist
directory.Your
build:digitalocean
script is trying to install dependencies, build the project, install production dependencies only, and then start the app. This sequence seems a bit off. Typically, you’d build your app and then install only the production dependencies. Consider revising it to something like:This ensures that after the build, only necessary production dependencies are retained.
Also, make sure that the DigitalOcean App Platform is configured to execute the
build:digitalocean
script during the build stage. The platform should be set to use this specific build command to build your app correctly.If none of the above helps, you should double-check that the file path in the start script (
./dist/server.js
) is correct relative to the root of your project on the DigitalOcean App Platform.Let me know how it goes!
Best,
Bobby