我正在尝试通过 Web 界面将 Node.js 应用程序部署到 Heroku,连接 git 存储库。 部署过程中遇到如下错误。无法安装依赖项。
**Heroku 错误日志: **
-----> Building on the Heroku-22 stack
-----> Determining which buildpack to use for this app
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): 12.x
engines.npm (package.json): unspecified (use default)
Resolving node version 12.x...
Downloading and installing node 12.22.12...
Using default npm version: 6.14.16
-----> Installing dependencies
Installing node modules
npm ERR! Cannot read property 'aws-sdk' of undefined
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.XadcE/_logs/2024-03-10T17_02_48_371Z-debug.log
-----> Build failed
**package.json **
{
"name": "xxxx",
"version": "1.0.0",
"engines": {
"node": "12.x"
},
"description": "Backend APIs for Customer microservice",
"main": "server.js",
"bin": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
"start:prod": "node server.js",
"start:dev": "nodemon server.js"
},
"pkg": {
"scripts": "build/**/*.js",
"assets": [
"controllers/**/*",
"database/**/*",
"functions/*",
"node_modules/**.*",
"routes/**/*"
],
"targets": [
"node12-macos-x64",
"node12-win-x64",
"node12-linux-x64"
],
"outputPath": "build"
},
"author": "xxxxx",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.1381.0",
"bcrypt": "^5.1.0",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"csv-parser": "^3.0.0",
"csvtojson": "^2.0.10",
"dotenv": "^16.0.0",
"express": "^4.17.2",
"express-session": "^1.17.3",
"fs": "0.0.1-security",
"jsonwebtoken": "^9.0.0",
"moment": "^2.29.1",
"mysql2": "^2.3.3",
"path": "^0.12.7",
"sequelize": "^6.15.1",
"twilio": "^3.84.1",
"@vonage/server-sdk": "^3.13.1"
},
"devDependencies": {
"concurrently": "^8.2.2",
"nodemon": "^3.0.3"
}
}
我的其他 Heroku 部署也有非常相似的 package.json。 知道这里可能出了什么问题吗?
npm i
并提交新的 package-lock.json您应该考虑更新节点版本。此错误可能是由于兼容性问题造成的。 根据 Heroku 文档:
Heroku 支持当前版本的 Node.js 和所有 Active 长期支持 (LTS) 版本。 Heroku 支持新版本 Node团队24小时正式发布。作为 Node.js 发布时间表说明,Heroku 目前支持 Node.js 版本 18.x 和 20.x.
您可以在这篇 Heroku 文章中找到更多详细信息:https://devcenter.heroku.com/articles/nodejs-support