我将我的应用程序本地构建到dist
文件夹中; package.json也复制在
npm install --production
在dist文件夹
dist
文件夹
Zip已上传到服务器,并在其中解压缩
尝试在服务器上运行该应用程序会导致Error: cannot find module <module_name>
除非我在解压缩
之后手动运行npm install <module_name>
,否则任何模块都会出现此错误
如果我从dist
文件夹中运行它,一切正常,所以它不是预压缩部分的问题
解压后运行npm install --production
并未解决任何问题(只是说所有模块都是最新的)
在服务器上删除node_modules
,然后运行npm install --production
可以使一切正常
在本地解压缩zip文件然后运行应用程序正常
我错过了什么/做错了什么?
编辑:package.json:
{
"name": "app-name",
"version": "0.0.1",
"scripts": {
"start": "index.js"
},
"dependencies": {
"body-parser": "^1.18.2",
"email-validator": "^1.1.1",
"express": "^4.16.2",
"express-jwt": "^5.3.0",
"express-jwt-permissions": "^1.0.0",
"firebase-admin": "^5.5.1",
"jsonwebtoken": "^8.1.0",
"mailgun-js": "^0.13.1",
"mysql2": "^1.5.0",
"password-hash-and-salt": "^0.1.4",
"randomstring": "^1.1.5",
"reflect-metadata": "^0.1.10",
"sequelize": "^4.22.6",
"sequelize-typescript": "^0.5.0"
},
"devDependencies": {
"@types/express": "^4.0.39",
"@types/express-jwt": "0.0.38",
"@types/jsonwebtoken": "^7.2.4",
"@types/node": "^8.0.51",
"@types/sequelize": "^4.0.79",
"babel-core": "^6.26.0",
"del": "^3.0.0",
"gulp": "^3.9.1",
"gulp-babel": "^7.0.0",
"gulp-ssh": "^0.6.0",
"gulp-typescript": "^3.2.3",
"gulp-zip": "^4.0.0",
"merge-stream": "^1.0.1",
"typescript": "^2.6.1"
}
}
答案 0 :(得分:0)
使用npm install --only = production。根据{{3}}
希望这有帮助,我是Node js的新手,只是想帮助