I must deploy my node.js + express rest api server and I chose google cloud’s app engine standard environment. Locally my server work as I expected but when deploying on gcloud I always get the error “Cannot find module ‘sequelize'”. Sequelize is in the dependecies of my package.json and I can’t figure out how to make it work.
//app.yaml
runtime: nodejs20
env: standard
instance_class: F2
env_variables:
DB_HOST: 'localhost'
DB_PORT: '3306'
DB_USER: 'user'
DB_PASSWORD: 'password'
DB_DATABASE: 'seinfeld_episodes'
DB_TEST_DATABASE: 'seinfeld_episode_test'
GOOGLE_NODE_RUN_SCRIPTS: ''
package.json
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"install-deps": "npm install",
"gcp-build": "npm install",
"build": "npm install",
"start": "node ./index.js",
"test": "cross-env NODE_ENV=test jest --testTimeout=5000"
},
"engines":{
"node": "20.x"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"faker": "^5.5.3",
"jasmine-node": "^1.16.0",
"joi": "^17.12.3",
"jsonwebtoken": "^9.0.2",
"mysql": "^2.18.1",
"mysql2": "^3.9.6",
"nodemon": "^3.1.0",
"sequelize": "^6.37.3",
"sequelize-cli": "^6.6.2",
"supertest": "^6.3.4",
"uuid": "^9.0.1"
},
"devDependencies": {
"chai": "^5.1.0",
"jest": "^29.7.0",
"mocha": "^10.4.0",
"sequelize": "^6.37.3",
"sequelize-mock": "^0.10.2",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7"
}
}
also as for refference, this is where the file where the code breaks:
database.js
const Sequelize = require('sequelize');
require('dotenv').config();
const sequelize = new Sequelize({
dialect: 'mysql',
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_DATABASE,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
});
module.exports = { sequelize };
and also the error log:
2024-05-11 06:33:39 default[20240511t093202] "GET /favicon.ico HTTP/1.1" 503
2024-05-11 06:33:39 default[20240511t093202] node:internal/modules/cjs/loader:1146
2024-05-11 06:33:39 default[20240511t093202] throw err;
2024-05-11 06:33:39 default[20240511t093202] ^
2024-05-11 06:33:39 default[20240511t093202] Error: Cannot find module 'sequelize'
2024-05-11 06:33:39 default[20240511t093202] Require stack:
2024-05-11 06:33:39 default[20240511t093202] - /workspace/database.js
2024-05-11 06:33:39 default[20240511t093202] - /workspace/models/episode.model.js
2024-05-11 06:33:39 default[20240511t093202] - /workspace/routes/episodes.route.js
2024-05-11 06:33:39 default[20240511t093202] - /workspace/app.js
2024-05-11 06:33:39 default[20240511t093202] - /workspace/index.js
2024-05-11 06:33:39 default[20240511t093202] at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
2024-05-11 06:33:39 default[20240511t093202] at Module._load (node:internal/modules/cjs/loader:984:27)
2024-05-11 06:33:39 default[20240511t093202] at Module.require (node:internal/modules/cjs/loader:1231:19)
2024-05-11 06:33:39 default[20240511t093202] at require (node:internal/modules/helpers:179:18)
2024-05-11 06:33:39 default[20240511t093202] at Object.<anonymous> (/workspace/database.js:1:20)
2024-05-11 06:33:39 default[20240511t093202] at Module._compile (node:internal/modules/cjs/loader:1369:14)
2024-05-11 06:33:39 default[20240511t093202] at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
2024-05-11 06:33:39 default[20240511t093202] at Module.load (node:internal/modules/cjs/loader:1206:32)
2024-05-11 06:33:39 default[20240511t093202] at Module._load (node:internal/modules/cjs/loader:1022:12)
2024-05-11 06:33:39 default[20240511t093202] at Module.require (node:internal/modules/cjs/loader:1231:19) {
2024-05-11 06:33:39 default[20240511t093202] code: 'MODULE_NOT_FOUND',
2024-05-11 06:33:39 default[20240511t093202] requireStack: [
2024-05-11 06:33:39 default[20240511t093202] '/workspace/database.js',
2024-05-11 06:33:39 default[20240511t093202] '/workspace/models/episode.model.js',
2024-05-11 06:33:39 default[20240511t093202] '/workspace/routes/episodes.route.js',
2024-05-11 06:33:39 default[20240511t093202] '/workspace/app.js',
2024-05-11 06:33:39 default[20240511t093202] '/workspace/index.js'
2024-05-11 06:33:39 default[20240511t093202] ]
2024-05-11 06:33:39 default[20240511t093202] }
2024-05-11 06:33:39 default[20240511t093202] Node.js v20.12.2
I tried reinstalling the sequelize module, I kept updating the package.json file in hopes for gcloud to recognize the module but everything I did didn’t seem to work.
Jurnal Video is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.