I'm trying to develope a express api with es6 style. Everything is fine when testing on my IDE, which is win10. Then I deploy to the EBS for production envirnoment test, It give me the ERR_MODULE_NOT_FOUND error.
All error given by the npm library, like cors, bcrypt, randomstring, etc. But not all library got problems.
Is it something difference when I run a es6 program on the EBS, because EBS is using linux as OS.
How can I solve it?
Here is the complete error message:
Sep 6 10:14:49 ip-172-31-26-145 web: > node www.js
Sep 6 10:14:49 ip-172-31-26-145 web: internal/process/esm_loader.js:74
Sep 6 10:14:49 ip-172-31-26-145 web: internalBinding('errors').triggerUncaughtException(
Sep 6 10:14:49 ip-172-31-26-145 web: ^
Sep 6 10:14:49 ip-172-31-26-145 web: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'cors' imported from /var/app/current/www.js
Sep 6 10:14:49 ip-172-31-26-145 web: at new NodeError (internal/errors.js:322:7)
Sep 6 10:14:49 ip-172-31-26-145 web: at packageResolve (internal/modules/esm/resolve.js:732:9)
Sep 6 10:14:49 ip-172-31-26-145 web: at moduleResolve (internal/modules/esm/resolve.js:773:18)
Sep 6 10:14:49 ip-172-31-26-145 web: at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:887:11)
Sep 6 10:14:49 ip-172-31-26-145 web: at Loader.resolve (internal/modules/esm/loader.js:89:40)
Sep 6 10:14:49 ip-172-31-26-145 web: at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
Sep 6 10:14:49 ip-172-31-26-145 web: at ModuleWrap. (internal/modules/esm/module_job.js:76:40)
Sep 6 10:14:49 ip-172-31-26-145 web: at link (internal/modules/esm/module_job.js:75:36) {
Sep 6 10:14:49 ip-172-31-26-145 web: code: 'ERR_MODULE_NOT_FOUND'
Sep 6 10:14:49 ip-172-31-26-145 web: }
Sep 6 10:14:49 ip-172-31-26-145 web: npm ERR! code ELIFECYCLE
Sep 6 10:14:49 ip-172-31-26-145 web: npm ERR! errno 1
Sep 6 10:14:49 ip-172-31-26-145 web: npm ERR! timesheet-api@0.0.0 start:node www.js
Sep 6 10:14:49 ip-172-31-26-145 web: npm ERR! Exit status 1
Sep 6 10:14:49 ip-172-31-26-145 web: npm ERR!
Sep 6 10:14:49 ip-172-31-26-145 web: npm ERR! Failed at the timesheet-api@0.0.0 start script.
Sep 6 10:14:49 ip-172-31-26-145 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Sep 6 10:14:49 ip-172-31-26-145 web: npm ERR! A complete log of this run can be found in:
Sep 6 10:14:49 ip-172-31-26-145 web: npm ERR! /home/webapp/.npm/_logs/2022-09-06T10_14_49_923Z-debug.log
And this is how I import the library:
import express from "express";
import path from "path";
import cookieParser from "cookie-parser";
import logger from "morgan";
import { fileURLToPath } from "url";
import passport from "passport";
import passportConfig from "./modules/passport.js";
import Debug from "debug";
import Cors from "cors";
Here is my full package.json:
{
"name": "test-api",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"dependencies": {
"bcrypt": "^5.0.1",
"big.js": "^6.2.1",
"cookie-parser": "~1.4.4",
"cors": "^2.8.5",
"debug": "^2.6.9",
"dotenv": "^16.0.1",
"express": "^4.17.1",
"https": "^1.0.0",
"jsonwebtoken": "^8.5.1",
"knex": "^2.0.0",
"lodash": "^4.17.21",
"module-alias": "^2.2.2",
"moment": "^2.29.3",
"moment-timezone": "^0.5.34",
"morgan": "~1.9.1",
"nodemon": "^2.0.16",
"passport": "^0.6.0",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"pdfmake": "^0.2.5",
"randomstring": "^1.2.2",
"tedious": "^14.5.0",
"uuid": "^8.3.2"
}
}