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 it39 Replies
Project ID:
c6ca0595-0c87-41e5-b4bd-6daab765702b
c6ca0595-0c87-41e5-b4bd-6daab765702b
Did you try and build it locally to see the placement of directories etc?
@Slashiy Thanks, yes, this worked as expected with no error.
When did it fail?
In deployment on railway
When it tried to run "npm run start"?
That is my guess
should be visible in the logs
This is in the deployment logs
npm WARN config production Use
--omit=dev
instead.
[email protected] start node ./dist/index.jsnode: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: [] }
show me the start script please?
@Brody Is there anything I need to show you that is not above?
what node version do you use on your local computer
Yeah it runs on my local version, I have it set to 18.16
your local version is 18.16 correct?
yes
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 repoDo we want 18 exactly? Or any version of 18
whatever 18.x.x version nixpacks wants to install will be fine
little tip, enclose code in triple back ticks
you are doing only 1 back tick
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
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 madegotcha
correct, try it again
it may still fail, I'm not exactly a js/ts dev mind you
Thanks
Here is what I am getting now
can you show me the dist folder on your local computer
that's the contents of the dist folder?
Yes
why there a src folder in the dist folder
keep in mind I'm still not a js/ts dev
Yeah I'm not sure, it's all js compiled from TS
do you have a repo I could look at?
Unfortunately it is a private repo and I can't let any outsiders in
screenshot of the github repo if possible?
just the section of the site that shows the folders
Was a problem with my local /dist not matching the backend thanks!
care to explain for anyone who might come across this thread in the future?
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!