在本地托管时,我的应用程序运行良好,但是当我尝试部署内部版本时,输出以下日志失败:
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 8.10.0
engines.npm (package.json): 6.4.1
Resolving node version 8.10.0...
Downloading and installing node 8.10.0...
Bootstrapping npm 6.4.1 (replacing 5.6.0)...
npm 6.4.1 installed
-----> Restoring cache
Cached directories were not restored due to a change in version of node, npm, yarn or stack
Module installation may take longer for this build
-----> Building dependencies
Installing node modules (package.json + package-lock)
npm ERR! code EINVALIDTYPE
npm ERR! typeerror Error: Argument #5: Expected object but got string
npm ERR! typeerror at inflatableChild (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/lib/install/inflate-shrinkwrap.js:93:3)
npm ERR! typeerror at BB.each (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/lib/install/inflate-shrinkwrap.js:55:12)
npm ERR! typeerror at tryCatcher (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
npm ERR! typeerror at Object.gotValue (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/reduce.js:155:18)
npm ERR! typeerror at Object.gotAccum (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/reduce.js:144:25)
npm ERR! typeerror at Object.tryCatcher (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
npm ERR! typeerror at Promise._settlePromiseFromHandler (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
npm ERR! typeerror at Promise._settlePromise (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
npm ERR! typeerror at Promise._settlePromise0 (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
npm ERR! typeerror at Promise._settlePromises (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:693:18)
npm ERR! typeerror at Async._drainQueue (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:133:16)
npm ERR! typeerror at Async._drainQueues (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:143:10)
npm ERR! typeerror at Immediate.Async.drainQueues (/tmp/build_8521c67f1a08023343c4f34aedc664fb/.heroku/node/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:17:14)
npm ERR! typeerror at runCallback (timers.js:794:20)
npm ERR! typeerror at tryOnImmediate (timers.js:752:5)
npm ERR! typeerror at processImmediate [as _immediateCallback] (timers.js:729:5)
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.Mus2Z/_logs/2018-11-18T01_38_26_671Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
If you're stuck, please submit a ticket so we can help:
https://help.heroku.com/
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
这是我的package.json文件:
{
"name": "scheduling",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"postinstall": "ng build --aot --target=production"
},
"engines": {
"node": "8.10.0",
"npm" : "6.4.1"
},
"repository": {
"type": "git",
"url": "https://github.com/ActionPackedJack/Restaurant-Schedule"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@angular/cli": ">=1.0.3",
"@angular/compiler-cli": ">=4.0.0",
"express": "^4.16.3",
"jquery": "^3.3.1",
"mongoose": "^5.2.2",
"rxjs": "^6.2.1",
"rxjs-compat": "^6.2.1",
"typescript": ">=2.2.0"
}
}
这是我的server.js:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.set('port', (process.env.PORT || 5000));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended : true}))
var path = require('path');
app.use(express.static(path.join(__dirname, './public/dist/public/')));
app.get('/*', function(req,res){
res.sendFile(path.join(__dirname, '/public/dist'));
})
//app.set('views', path.join(__dirname, '/public/dist'))
require('./server/config/mongoose.js');
var routes_setter = require('./server/config/routes.js');
routes_setter(app);
app.listen(app.get('port'), function(){
console.log('Node app is running on port', app.get('port'))
});
我阅读了另一个用户实例,该实例通过删除他们的package-lock.json文件来解决此问题,但是尝试导致另一个错误,“ build命令需要在Angular项目中运行,但是项目定义可以找不到。”
任何想法都将不胜感激,请谢谢!
答案 0 :(得分:0)
您的package.json没有devDependencies,需要吗?
我点击了以下链接: https://medium.com/@hellotunmbi/how-to-deploy-angular-application-to-heroku-1d56e09c5147 但请注意他的更新链接以获取更新: https://medium.com/@shubhsharma10/how-to-deploy-angular-6-app-to-heroku-52b73ac7a3aa
我的heroku应用程序中的package.json文件如下:
{
"name": "my-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot --prod"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.0.0",
"@angular/common": "~7.0.0",
"@angular/compiler": "~7.0.0",
"@angular/compiler-cli": "^7.0.3",
"@angular/core": "~7.0.0",
"@angular/forms": "~7.0.0",
"@angular/http": "~7.0.0",
"@angular/platform-browser": "~7.0.0",
"@angular/platform-browser-dynamic": "~7.0.0",
"@angular/router": "~7.0.0",
"angular-font-awesome": "^3.1.2",
"bootstrap": "^4.1.3",
"core-js": "^2.5.4",
"curl": "^0.1.4",
"express": "^4.16.4",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"latest": "^0.2.0",
"path": "^0.12.7",
"popper.js": "^1.12.9",
"rxjs": "^6.3.3",
"typescript": "~3.1.1",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.10.0",
"@angular/cli": "^7.0.5",
"@angular/compiler-cli": "^7.0.3",
"@angular/language-service": "~7.0.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"enhanced-resolve": "^4.1.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.1"
},
"engines": {
"node": "10.12.0",
"npm": "6.4.1"
}
}