将 Mean.js 项目部署到 Heroku 时出现 TypeError

Get TypeError When deploying A Mean.js Project into Heroku

这是一个旧的 mean.js 项目。项目 node 版本 4.4.4。我可以使用 node 10.24.1.

在本地机器上 运行 这个项目

当我在 heroku 中部署这个项目时,许多 TypeErrorsterminal 进入 node-modules 包下载。我按照一些答案来解决这个问题,但不幸的是我不能成功,这就是我在这里问的原因。

我的 package-lock 文件已更新。

Build Logs如下:

Enumerating objects: 28099, done.
Counting objects: 100% (28099/28099), done.
Delta compression using up to 6 threads
Compressing objects: 100% (15109/15109), done.
Writing objects: 100% (28099/28099), 58.86 MiB | 343.00 KiB/s, done.
Total 28099 (delta 10970), reused 27836 (delta 10797), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Deleting 1 files matching .slugignore patterns.
remote: -----> Determining which buildpack to use for this app
remote: -----> Node.js app detected
remote:        
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        
remote: -----> Installing binaries
remote:        engines.node (package.json):  4.4.4
remote:        engines.npm (package.json):   3.8.x
remote:        
remote:        Resolving node version 4.4.4...
remote:        Downloading and installing node 4.4.4...
remote:        Bootstrapping npm 3.8.x (replacing 2.15.1)...
remote:        npm 3.8.x installed
remote:        
remote: -----> Installing dependencies
remote:        Installing node modules (package.json + package-lock)
remote:        npm ERR! Linux 4.4.0-1101-aws
remote:        npm ERR! argv "/tmp/build_648a0567/.heroku/node/bin/node" "/tmp/build_648a0567/.heroku/node/bin/npm" "install" "--production=false" "--unsafe-perm" "--userconfig" "/tmp/build_648a0567/.npmrc"
remote:        npm ERR! node v4.4.4
remote:        npm ERR! npm  v3.8.9
remote:        npm ERR! code EMISSINGARG
remote:        
remote:        npm ERR! typeerror Error: Missing required argument #1
remote:        npm ERR! typeerror     at andLogAndFinish (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:31:3)
remote:        npm ERR! typeerror     at fetchPackageMetadata (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:51:22)
remote:        npm ERR! typeerror     at resolveWithNewModule (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/install/deps.js:455:12)
remote:        npm ERR! typeerror     at /tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/install/deps.js:456:7
remote:        npm ERR! typeerror     at /tmp/build_648a0567/.heroku/node/lib/node_modules/npm/node_modules/iferr/index.js:13:50
remote:        npm ERR! typeerror     at /tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:37:12
remote:        npm ERR! typeerror     at addRequestedAndFinish (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:82:5)
remote:        npm ERR! typeerror     at returnAndAddMetadata (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:118:7)
remote:        npm ERR! typeerror     at pickVersionFromRegistryDocument (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:135:20)
remote:        npm ERR! typeerror     at /tmp/build_648a0567/.heroku/node/lib/node_modules/npm/node_modules/iferr/index.js:13:50
remote:        npm ERR! typeerror This is an error with npm itself. Please report this error at:
remote:        npm ERR! typeerror     <http://github.com/npm/npm/issues>
remote:        npm ERR! Linux 4.4.0-1101-aws
remote:        npm ERR! argv "/tmp/build_648a0567/.heroku/node/bin/node" "/tmp/build_648a0567/.heroku/node/bin/npm" "install" "--production=false" "--unsafe-perm" "--userconfig" "/tmp/build_648a0567/.npmrc"
remote:        npm ERR! node v4.4.4
remote:        npm ERR! npm  v3.8.9
remote:        npm ERR! code EMISSINGARG
remote:        
remote:        npm ERR! typeerror Error: Missing required argument #1
remote:        npm ERR! typeerror     at andLogAndFinish (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:31:3)
remote:        npm ERR! typeerror     at fetchPackageMetadata (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:51:22)
remote:        npm ERR! typeerror     at resolveWithNewModule (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/install/deps.js:455:12)
remote:        npm ERR! typeerror     at /tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/install/deps.js:456:7
remote:        npm ERR! typeerror     at /tmp/build_648a0567/.heroku/node/lib/node_modules/npm/node_modules/iferr/index.js:13:50
remote:        npm ERR! typeerror     at /tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:37:12
remote:        npm ERR! typeerror     at addRequestedAndFinish (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:82:5)
remote:        npm ERR! typeerror     at returnAndAddMetadata (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:118:7)
remote:        npm ERR! typeerror     at pickVersionFromRegistryDocument (/tmp/build_648a0567/.heroku/node/lib/node_modules/npm/lib/fetch-package-metadata.js:135:20)
remote:        npm ERR! typeerror     at /tmp/build_648a0567/.heroku/node/lib/node_modules/npm/node_modules/iferr/index.js:13:50
remote:        npm ERR! typeerror This is an error with npm itself. Please report this error at:
remote:        npm ERR! typeerror     <http://github.com/npm/npm/issues>
remote:        
remote:        npm ERR! Please include the following file with any support request:
remote:        npm ERR!     /tmp/build_648a0567/npm-debug.log
remote: 
remote: -----> Build failed

package.json 文件

{
  "name": "...",
  "description": "Full-Stack JavaScript with MongoDB, Express, AngularJS, and Node.js",
  "version": "0.0.1",
  "author": "...",
  "engines": {
    "node": "4.4.4",
    "npm": "3.8.x"
  },
  "scripts": {
    "start": "grunt",
    "debug": "grunt debug",
    "test": "grunt test",
    "postinstall": "bower install --config.interactive=false"
  },
  "dependencies": {
    "async": "~0.9.0",
    "body-parser": "~1.9.0",
    "bower": "~1.3.8",
    "chalk": "~0.5",
    "compression": "~1.2.0",
    "connect-flash": "~0.1.1",
    "connect-mongo": "^1.1.0",
    "connect-mongodb-session": "^2.1.1",
    "consolidate": "~0.10.0",
    "cookie-parser": "~1.3.2",
    "dotenv": "^16.0.0",
    "express": "^4.13.4",
    "express-session": "^1.13.0",
    "forever": "~0.11.0",
    "glob": "~4.0.5",
    "gridfs-stream": "^1.1.1",
    "grunt-cli": "~0.1.13",
    "helmet": "~0.5.0",
    "lodash": "^4.12.0",
    "method-override": "~2.3.0",
    "mongoose": "4.7.3",
    "morgan": "~1.4.1",
    "multer": "^1.1.0",
    "nodemailer": "~2.4.1",
    "passport": "~0.2.0",
    "passport-facebook": "~1.0.2",
    "passport-github": "~0.1.5",
    "passport-google-oauth": "~0.1.5",
    "passport-linkedin": "~0.1.3",
    "passport-local": "~1.0.0",
    "passport-twitter": "~1.0.2",
    "paypal-rest-sdk": "^1.6.8",
    "q": "^1.5.1",
    "stripe": "^4.6.0",
    "swig": "~1.4.1",
    "validator": "^5.2.0"
  },
  "devDependencies": {
    "grunt": "^1.0.1",
    "grunt-concurrent": "^2.3.0",
    "grunt-contrib-csslint": "^1.0.0",
    "grunt-contrib-cssmin": "^1.0.1",
    "grunt-contrib-jshint": "^1.0.0",
    "grunt-contrib-uglify": "^1.0.1",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-env": "^0.4.4",
    "grunt-karma": "^1.0.0",
    "grunt-mocha-test": "^0.12.7",
    "grunt-ng-annotate": "^2.0.2",
    "grunt-nodemon": "^0.4.2",
    "karma": "^0.13.22",
    "karma-chrome-launcher": "^1.0.1",
    "karma-coverage": "^1.0.0",
    "karma-firefox-launcher": "^0.1.7",
    "karma-jasmine": "^1.0.2",
    "karma-phantomjs-launcher": "^1.0.0",
    "load-grunt-tasks": "^3.5.0",
    "mocha": "^2.4.5",
    "should": "^8.3.1",
    "supertest": "^1.2.0"
  }
}

因为这个项目是 运行 在我本地机器上的 node 10.24.1 上,如果 heroku's node version 降级为 10.24.1 在 运行 时间(如果可能),我假设但我不确定。

请任何人回答这个问题或建议?提前致谢!

Node.js 4.4.4绝对是古老.

它甚至没有出现在 this page of releases 上,部分内容是:

After six months, odd-numbered releases (9, 11, etc.) become unsupported, and even-numbered releases (10, 12, etc.) move to Active LTS status and are ready for general use. LTS release status is "long-term support", which typically guarantees that critical bugs will be fixed for a total of 30 months.

4.4 版已经过维护 window,我强烈 敦促您升级此项目。

话虽如此,您很有可能将 Heroku 升级到 运行 Node.js 10 以匹配您的本地版本。 Heroku only officially supports the current and active LTS releases, but it doesn't prevent you from using older releases:

Since Heroku is based on a standard Ubuntu Linux stack, you can run most Node versions (>= 0.10.0) on the platform. However, the testing and support focus of the buildpack will be oriented around active LTS and Stable releases.

更新 package.json 中的 engines 部分:

  "engines": {
    "node": "10.x"
  },

我还删除了此处的 npm 版本,这应该会导致 Heroku 使用与最新 Node.js 10.x 版本捆绑的任何版本。

提交此更改,然后重新部署。