I'm attempting to deploy my Node.js server on Render, but I'm encountering an error during deployment. The error seems to be related to a module not being found.
Error Log:
requireStack: []
code: 'MODULE_NOT_FOUND',
at internal/main/run_main_module.js:17:47 {
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
Error: Cannot find module '/opt/render/project/src/build/src/index.js'
^
throw err;
internal/modules/cjs/loader.js:905
==> Running 'node build/src/index.js'
==> Docs on specifying a bun version: https://render.com/docs/bun-version
==> Using Bun version 1.1.0 (default)
==> Docs on specifying a Node version: https://render.com/docs/node-version
==> Using Node version 14.18.0 via /opt/render/project/src/package.json
}
requireStack: []
code: 'MODULE_NOT_FOUND',
at internal/main/run_main_module.js:17:47 {
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
Error: Cannot find module '/opt/render/project/src/build/src/index.js'
^
throw err;
internal/modules/cjs/loader.js:905
==> Running 'node build/src/index.js'
==> Docs on specifying a bun version: https://render.com/docs/bun-version
==> Using Bun version 1.1.0 (default)
==> Docs on specifying a Node version: https://render.com/docs/node-version
==> Using Node version 14.18.0 via /opt/render/project/src/package.json
}
requireStack: []
code: 'MODULE_NOT_FOUND',
at internal/main/run_main_module.js:17:47 {
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
Error: Cannot find module '/opt/render/project/src/build/src/index.js'
^
throw err;
internal/modules/cjs/loader.js:905
==> Running 'node build/src/index.js'
==> Docs on specifying a bun version: https://render.com/docs/bun-version
==> Using Bun version 1.1.0 (default)
==> Docs on specifying a Node version: https://render.com/docs/node-version
==> Using Node version 14.18.0 via /opt/render/project/src/package.json
}
> [email protected] build /opt/render/project/src
==> Running 'npm run build'
==> Docs on specifying a bun version: https://render.com/docs/bun-version
==> Using Bun version 1.1.0 (default)
==> Docs on specifying a Node version: https://render.com/docs/node-version
==> Using Node version 14.18.0 via /opt/render/project/src/package.json
package.json
{
"name": "all-chat-server",
"version": "0.0.0",
"description": "",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"files": [
"build/src"
],
"license": "Apache-2.0",
"keywords": [],
"scripts": {
"check-types": "tsc --noemit",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint src/**/*.ts",
"clean": "gts clean",
"fix": "gts fix",
"start": "node ./build/src/index.js",
"dev:tsc": "tsc -w",
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
"build": "tsc",
"prepare": "husky install"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.2",
"@types/buffer-to-stream": "^1.0.3",
"@types/connect-mongodb-session": "^2.4.3",
"@types/cookie-parser": "^1.4.7",
"@types/currency-formatter": "^1.5.1",
"@types/express-session": "^1.17.4",
"@types/fluent-ffmpeg": "^2.1.23",
"@types/fs-extra": "^11.0.2",
"@types/graphql-upload": "^8.0.11",
"@types/html-pdf-node": "^1.0.0",
"@types/jsonwebtoken": "^9.0.6",
"@types/lodash": "^4.14.182",
"@types/multer": "^1.4.7",
"@types/multer-s3": "^2.7.12",
"@types/node": "^14.11.2",
"@types/node-cron": "^3.0.7",
"@types/nodemailer": "^6.4.4",
"@types/passport": "^1.0.7",
"@types/passport-facebook": "^2.1.11",
"@types/passport-google-oauth20": "^2.0.11",
"@types/passport-linkedin-oauth2": "^1.5.3",
"@types/passport-local": "^1.0.34",
"@types/pdf-parse": "^1.1.4",
"@types/shortid": "0.0.29",
"@types/validator": "^13.7.2",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"gts": "^3.1.0",
"husky": "^8.0.3",
"typescript": "^4.0.3"
},
"dependencies": {
"@apollo/server": "^4.7.5",
"@aws-sdk/client-s3": "^3.496.0",
"@aws-sdk/credential-providers": "^3.496.0",
"@aws-sdk/lib-storage": "^3.496.0",
"@elastic/elasticsearch": "^8.10.0",
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@typegoose/typegoose": "^9.8.1",
"@types/download": "^8.0.2",
"@types/ws": "^8.5.3",
"apollo-server-core": "^3.7.0",
"apollo-server-express": "^3.7.0",
"bcryptjs": "^2.4.3",
"buffer-to-stream": "^1.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"cloudinary": "^2.1.0",
"connect-mongodb-session": "^3.1.1",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"cpy-cli": "^4.2.0",
"currency-formatter": "^1.5.9",
"date-fns": "^2.29.3",
"docxtemplater": "^3.44.0",
"dotenv": "^16.0.1",
"download": "^8.0.0",
"express": "^4.18.1",
"express-async-errors": "^3.1.1",
"express-session": "^1.17.3",
"ffmpeg": "^0.0.4",
"fluent-ffmpeg": "^2.1.2",
"fs-extra": "^11.1.1",
"graphql": "15.x",
"graphql-mongoose-subscriptions": "^1.0.14",
"graphql-passport": "^0.6.4",
"graphql-type-json": "^0.3.2",
"graphql-upload": "^13.0.0",
"graphql-ws": "^5.10.1",
"handlebars": "^4.7.7",
"html-pdf-node": "^1.0.8",
"https": "^1.0.0",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
"mammoth": "^1.6.0",
"moment": "^2.29.3",
"mongoose": "^6.3.3",
"multer": "^1.4.5-lts.1",
"multer-s3": "^3.0.1",
"netlify-lambda": "^2.0.16",
"node-cron": "^3.0.2",
"nodemailer": "^6.7.5",
"openai": "^4.20.0",
"passport": "^0.5.0",
"passport-facebook": "^3.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-linkedin-oauth2": "^2.0.0",
"passport-local": "^1.0.0",
"pdf-parse": "^1.1.1",
"pm2": "^5.3.1",
"prettier": "^3.1.1",
"puppeteer": "^22.0.0",
"reflect-metadata": "^0.1.13",
"revai-node-sdk": "^3.6.2",
"serverless-http": "^3.2.0",
"shortid": "^2.2.16",
"socket.io": "^4.5.1",
"stripe": "^9.16.0",
"ts-node-dev": "^1.1.8",
"type-graphql": "^1.1.1",
"typedi": "^0.10.0",
"uuidv4": "^6.2.13",
"ws": "^8.8.1",
"xlsx": "^0.18.5"
},
"optionalDependencies": {
"fsevents": "*"
},
"engines": {
"node": "14.18.0"
}
}
Here is the Render build command
npm install; npm run build
Here is Render start command
node build/src/index.js
Any insights into what might be causing this issue or how to resolve it would be greatly appreciated. Thank you!
Error: Cannot find module '/opt/render/project/src/build/src/index.js'
The error tells me index.js
is not located in src/build/src/index.js
.
You need to build the project locally and find the location of index.js
inside Typescript's output directory. You can get the output directory from your Typescript configuration.
After that, change the start command accordingly. If, for instance, it's located in ./dist
, the start command must be node ./dist/index.js
.