我一直在尝试将Angular Universal应用程序部署到heroku
无论我做什么,都会返回相同的错误 “无法编译Node.js应用程序。”
我已经设置了一个procfile,我已经指定了“引擎” (我已尝试过脚本的开头和结尾),
我已经将一些包形式的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"
}
}
答案 0 :(得分:1)
这在NPM文档的the common errors section中有描述:
无效的JSON
Error: Invalid JSON npm ERR! SyntaxError: Unexpected token < npm ERR! registry error parsing json
- 可能的临时npm注册表故障或损坏的本地服务器缓存。运行
npm cache clean
和/或稍后再试。- 这可能是由向
package.json
个请求提供HTML响应的公司代理引起的。检查npm的代理configuration。- 检查您尝试安装的软件包是否存在问题(例如无效
package.json
)。
您的package.json
包含有效的JSON。请尝试检查package.lock
。
答案 1 :(得分:0)
最后,这与我如何推动heroku
有关因为我在一个分支上,我应该一直在使用:
git add .
git commit -m"message"
git push heroku <branchname:>master