将 Angular Universal 部署到 heroku,无法编译 Node.js 应用程序

Deploy Angular Universal to heroku, failed to compile Node.js app

我一直在尝试将 Angular 通用应用程序部署到 heroku

无论我做什么都返回同样的错误 "failed to compile Node.js app."

我已经设置了一个 procfile,我已经指定 "engines" (我在脚本的开头和结尾都试过了),

我已经将一些包从 devDependencies 移动到 package.json 中的依赖项(在某一时刻将所有包放入依赖项)

我试过了,正在提交我的节点文件夹。

我什至使用了完全不同的 package.json 它仍然给我完全相同的响应!!?

这告诉我;我认为,它与依赖关系无关,我正在为这个项目使用?

使用:

git add .
git commit -m"message"
git push heroku master

回复:

Compressing objects: 100% (252/252), done.
Writing objects: 100% (256/256), 3.20 MiB | 319.00 KiB/s, done.
Total 256 (delta 116), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
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):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 8.x...
remote:        Downloading and installing node 8.11.2...
remote:        Using default npm version: 5.6.0
remote:
remote: -----> Restoring cache
remote:        Skipping cache restore (not-found)
remote:
remote: -----> Building dependencies
remote:        Installing node modules (package.json + package-lock)
remote:        npm ERR! Unexpected token < in JSON at position 108
remote:
remote:        npm ERR! A complete log of this run can be found in:
remote:        npm ERR!     /tmp/npmcache.j8wgx/_logs/2018-05-21T14_34_17_856Z-debug.log
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        Some possible problems:
remote:
remote:        - Node version not specified in package.json
remote:        https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to ma-leon.
remote:
To https://git.heroku.com/ma-leon.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/ma-leon.git'

我的package.json:

{
  "name": "maleon",
  "version": "1.0.0",
  "license": "MIT",
  "main": "index.js",
  "scripts": {
    "ng": "ng",
    "start": "node index.js",
    "build:es2015": "node node_modules/babel-cli/bin/babel.js node_modules/ngx-page-scroll/ --out-dir node_modules/ngx-page-scroll/ --presets es2015",
    "postinstall": "npm run build:es2015  &&  ng build --prod && ng build --prod --app 1 --output-hashing none",
    "fix-scroll": "node node_modules/babel-cli/bin/babel.js node_modules/ngx-page-scroll/ --out-dir node_modules/ngx-page-scroll/ --presets es2015",
    "lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.10",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.10",
    "@angular/forms": "^5.2.10",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/platform-server": "^5.2.10",
    "@angular/router": "^5.2.0",
    "@nguniversal/express-engine": "^5.0.0",
    "@nguniversal/module-map-ngfactory-loader": "^5.0.0",
    "babel-cli": "^6.26.0",
    "body-parser": "^1.17.1",
    "bootstrap": "^3.3.7",
    "core-js": "^2.5.3",
    "express": "^4.15.2",
    "emailjs": "^1.0.10",
    "jquery": "^3.2.1",
    "linkify": "^0.2.1",
    "linkifyjs": "^2.1.6",
    "ng2-bootstrap": "^1.6.3",
    "ngx-page-scroll": "^4.0.2",
    "rxjs": "^5.2.0",
    "socket.io-client": "^1.7.3",
    "ts-helpers": "^1.1.1",
    "web-animations-js": "^2.2.5",
    "zone.js": "0.8.5"
  },
  "devDependencies": {
    "@angular/cli": "~1.7.4",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "babel-polyfill": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "popper.js": "^1.14.3",
    "protractor": "~5.1.2",
    "request": "^2.81.0",
    "smoothscroll-polyfill": "^0.4.0",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  },
  "engines": {
    "node": "9.x"
  }
}

这在 NPM 文档的 the common errors section 中有描述:

Invalid JSON

Error: Invalid JSON

npm ERR! SyntaxError: Unexpected token <

npm ERR! registry error parsing json
  • Possible temporary npm registry glitch, or corrupted local server cache. Run npm cache clean and/or try again later.
  • This can be caused by corporate proxies that give HTML responses to package.json requests. Check npm's proxy configuration.
  • Check that it's not a problem with a package you're trying to install (e.g. invalid package.json).

您的 package.json 包含有效的 JSON。尝试检查您的 package.lock.

最后,这与我如何推送到 heroku 有关

因为我在一个分支上,所以我应该使用:

git add .
git commit -m"message"
git push heroku <branchname:>master