Error: Cannot find module '/app/dist/index.js'

Hello, I have not made any significant changes to my app, but all of a sudden the build is failing. Here is my JSON NIXPACKS script { "$schema": "https://railway.app/railway.schema.json", "build": { "builder": "NIXPACKS", "buildCommand": "npm run build" }, "deploy": { "numReplicas": 1, "startCommand": "npm run start", "restartPolicyType": "ON_FAILURE", "restartPolicyMaxRetries": 10 } } And here is my tsconfig { "compilerOptions": { "module": "commonjs", "esModuleInterop": true, "target": "es6", "noImplicitAny": true, "noUnusedLocals": true, "noEmit": false, "moduleResolution": "node", "sourceMap": true, "skipLibCheck": true, "resolveJsonModule": true, "outDir": "dist", "baseUrl": ".", "strict": true, "paths": { "*": ["node_modules/*"] } }, "files": ["src/types/custom-express.d.ts"], "include": ["src/**/*"] } And my npm script { "name": "placeholder", "version": "1.0.0", "description": "", "main": "dist/index.js", "scripts": { "dev": "nodemon src/index.ts", "start": "node dist/index.js", "build": "tsc" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "nodemon": "^2.0.22", "prisma": "^4.12.0", "ts-node": "^10.9.1", "typescript": "^5.0.3" }, "dependencies": { "@prisma/client": "^4.12.0", "@types/express": "^4.17.17", "@types/luxon": "^3.3.0", "@types/node": "^18.15.11", "body-parser": "^1.20.2", "cors": "^2.8.5", "date-fns": "^2.29.3", "dotenv": "^16.0.3", "express": "^4.18.2", "firebase-admin": "^11.8.0", "jsonwebtoken": "^9.0.0", "luxon": "^3.3.0", "moment": "^2.29.4", "mysql2": "^2.3.3" } } Currently running on my machine with the same npm build npm start workflow. If you have any insight I would greatly appreciate it
39 Replies
Percy
Percy14mo ago
Project ID: c6ca0595-0c87-41e5-b4bd-6daab765702b
coloneljelly
coloneljelly14mo ago
c6ca0595-0c87-41e5-b4bd-6daab765702b
Slashiy
Slashiy14mo ago
Did you try and build it locally to see the placement of directories etc?
coloneljelly
coloneljelly14mo ago
@Slashiy Thanks, yes, this worked as expected with no error.
Slashiy
Slashiy14mo ago
When did it fail?
coloneljelly
coloneljelly14mo ago
In deployment on railway
Slashiy
Slashiy14mo ago
When it tried to run "npm run start"?
coloneljelly
coloneljelly14mo ago
That is my guess
Slashiy
Slashiy14mo ago
should be visible in the logs
coloneljelly
coloneljelly14mo ago
This is in the deployment logs npm WARN config production Use --omit=dev instead.
qas_express_app@1.0.0 start node ./dist/index.js
node:internal/modules/cjs/loader:988 throw err; ^ Error: Cannot find module '/app/dist/index.js' at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15) at Function.Module._load (node:internal/modules/cjs/loader:833:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:22:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }
Brody
Brody14mo ago
show me the start script please?
coloneljelly
coloneljelly14mo ago
@Brody Is there anything I need to show you that is not above?
Brody
Brody14mo ago
what node version do you use on your local computer
coloneljelly
coloneljelly14mo ago
Yeah it runs on my local version, I have it set to 18.16
Brody
Brody14mo ago
your local version is 18.16 correct?
coloneljelly
coloneljelly14mo ago
yes
Brody
Brody14mo ago
in your package.json file set engines.node = 18 then show me your new package.json just so I can make sure it's correct before you push the repo
coloneljelly
coloneljelly14mo ago
Do we want 18 exactly? Or any version of 18
Brody
Brody14mo ago
whatever 18.x.x version nixpacks wants to install will be fine
coloneljelly
coloneljelly14mo ago
{
"name": "qas_express_app",
"version": "1.0.0",
"description": "",
"engines.node": ">18.0",
"main": "dist/index.js",
"scripts": {
"dev": "nodemon src/index.ts",
"start": "node ./dist/index.js",
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.22",
"prisma": "^4.12.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.3"
},
"dependencies": {
"@prisma/client": "^4.12.0",
"@types/express": "^4.17.17",
"@types/luxon": "^3.3.0",
"@types/node": "^18.15.11",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"date-fns": "^2.29.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"firebase-admin": "^11.8.0",
"jsonwebtoken": "^9.0.0",
"luxon": "^3.3.0",
"moment": "^2.29.4",
"mysql2": "^2.3.3"
}
}
{
"name": "qas_express_app",
"version": "1.0.0",
"description": "",
"engines.node": ">18.0",
"main": "dist/index.js",
"scripts": {
"dev": "nodemon src/index.ts",
"start": "node ./dist/index.js",
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.22",
"prisma": "^4.12.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.3"
},
"dependencies": {
"@prisma/client": "^4.12.0",
"@types/express": "^4.17.17",
"@types/luxon": "^3.3.0",
"@types/node": "^18.15.11",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"date-fns": "^2.29.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"firebase-admin": "^11.8.0",
"jsonwebtoken": "^9.0.0",
"luxon": "^3.3.0",
"moment": "^2.29.4",
"mysql2": "^2.3.3"
}
}
Brody
Brody14mo ago
little tip, enclose code in triple back ticks you are doing only 1 back tick
coloneljelly
coloneljelly14mo ago
gotcha thank you If you can help me figure this out today I would be incredibly greatful, we have a client demo and this has been stable until today and we have no idea why
Brody
Brody14mo ago
engines.node is not a single string, engines is an object type and node is a string type inside the engines object also please specify a whole number 18 send the package.json again when these changes are made
coloneljelly
coloneljelly14mo ago
gotcha
{
"name": "qas_express_app",
"version": "1.0.0",
"description": "",
"engines": {
"node": "18"
},
"main": "dist/index.js",
"scripts": {
"dev": "nodemon src/index.ts",
"start": "node ./dist/index.js",
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.22",
"prisma": "^4.12.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.3"
},
"dependencies": {
"@prisma/client": "^4.12.0",
"@types/express": "^4.17.17",
"@types/luxon": "^3.3.0",
"@types/node": "^18.15.11",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"date-fns": "^2.29.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"firebase-admin": "^11.8.0",
"jsonwebtoken": "^9.0.0",
"luxon": "^3.3.0",
"moment": "^2.29.4",
"mysql2": "^2.3.3"
}
}
{
"name": "qas_express_app",
"version": "1.0.0",
"description": "",
"engines": {
"node": "18"
},
"main": "dist/index.js",
"scripts": {
"dev": "nodemon src/index.ts",
"start": "node ./dist/index.js",
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.22",
"prisma": "^4.12.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.3"
},
"dependencies": {
"@prisma/client": "^4.12.0",
"@types/express": "^4.17.17",
"@types/luxon": "^3.3.0",
"@types/node": "^18.15.11",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"date-fns": "^2.29.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"firebase-admin": "^11.8.0",
"jsonwebtoken": "^9.0.0",
"luxon": "^3.3.0",
"moment": "^2.29.4",
"mysql2": "^2.3.3"
}
}
Brody
Brody14mo ago
correct, try it again it may still fail, I'm not exactly a js/ts dev mind you
coloneljelly
coloneljelly14mo ago
Thanks Here is what I am getting now
qas_express_app@1.0.0 start
node:internal/modules/cjs/loader:998
^
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
code: 'MODULE_NOT_FOUND',
requireStack: []
Node.js v18.12.1
npm WARN config production Use `--omit=dev` instead.
> node ./dist/index.js
node:internal/modules/cjs/loader:998
throw err;
^
at Module._load (node:internal/modules/cjs/loader:841:27)
code: 'MODULE_NOT_FOUND',
requireStack: []
> node ./dist/index.js
^
Error: Cannot find module '/app/dist/index.js'
at Module._load (node:internal/modules/cjs/loader:841:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
}
qas_express_app@1.0.0 start
node:internal/modules/cjs/loader:998
^
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
code: 'MODULE_NOT_FOUND',
requireStack: []
Node.js v18.12.1
npm WARN config production Use `--omit=dev` instead.
> node ./dist/index.js
node:internal/modules/cjs/loader:998
throw err;
^
at Module._load (node:internal/modules/cjs/loader:841:27)
code: 'MODULE_NOT_FOUND',
requireStack: []
> node ./dist/index.js
^
Error: Cannot find module '/app/dist/index.js'
at Module._load (node:internal/modules/cjs/loader:841:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
}
Brody
Brody14mo ago
can you show me the dist folder on your local computer
coloneljelly
coloneljelly14mo ago
-rw-r--r--@ 1 1030 May 5 13:37 appRouter.js
-rw-r--r--@ 1 633 May 5 13:37 appRouter.js.map
drwxr-xr-x@ 13 416 May 5 13:32 controllers
drwxr-xr-x@ 6 192 May 5 13:32 db
-rw-r--r--@ 1 1033 May 5 13:37 index.js
-rw-r--r--@ 1 768 May 5 13:37 index.js.map
-rw-r--r--@ 1 2416 May 22 09:53 placeholder.json
drwxr-xr-x@ 16 512 May 5 13:32 routers
drwxr-xr-x@ 6 192 Apr 7 15:34 routes
drwxr-xr-x@ 11 352 May 22 08:50 src
-rw-r--r--@ 1 1030 May 5 13:37 appRouter.js
-rw-r--r--@ 1 633 May 5 13:37 appRouter.js.map
drwxr-xr-x@ 13 416 May 5 13:32 controllers
drwxr-xr-x@ 6 192 May 5 13:32 db
-rw-r--r--@ 1 1033 May 5 13:37 index.js
-rw-r--r--@ 1 768 May 5 13:37 index.js.map
-rw-r--r--@ 1 2416 May 22 09:53 placeholder.json
drwxr-xr-x@ 16 512 May 5 13:32 routers
drwxr-xr-x@ 6 192 Apr 7 15:34 routes
drwxr-xr-x@ 11 352 May 22 08:50 src
Brody
Brody14mo ago
that's the contents of the dist folder?
coloneljelly
coloneljelly14mo ago
coloneljelly
coloneljelly14mo ago
Yes
Brody
Brody14mo ago
why there a src folder in the dist folder keep in mind I'm still not a js/ts dev
coloneljelly
coloneljelly14mo ago
Yeah I'm not sure, it's all js compiled from TS
Brody
Brody14mo ago
do you have a repo I could look at?
coloneljelly
coloneljelly14mo ago
Unfortunately it is a private repo and I can't let any outsiders in
Brody
Brody14mo ago
screenshot of the github repo if possible? just the section of the site that shows the folders
coloneljelly
coloneljelly14mo ago
Was a problem with my local /dist not matching the backend thanks!
Brody
Brody14mo ago
care to explain for anyone who might come across this thread in the future?
coloneljelly
coloneljelly14mo ago
Yes, I guess resolveJSONModule in your .tsconfig can change the way that your build folder is organized. Be aware of changing your .tsconfig the Friday before a demo!