Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 部署到heroku 4_Node.js_Angular_Heroku - Fatal编程技术网

Node.js 部署到heroku 4

Node.js 部署到heroku 4,node.js,angular,heroku,Node.js,Angular,Heroku,我正在尝试将Angular 4商店应用程序部署到heroku 但这不是工作 这是我的package.json: { "name": "angular-simple-shopping-cart", "version": "1.0.0", "license": "MIT", "main": "app.js", "engines": { "node": ">= 8.5.0", "npm": ">= 5.3.0" }, "scripts": {

我正在尝试将Angular 4商店应用程序部署到heroku

但这不是工作

这是我的package.json:

{
  "name": "angular-simple-shopping-cart",
  "version": "1.0.0",
  "license": "MIT",
  "main": "app.js",
  "engines": {
    "node": ">= 8.5.0",
    "npm": ">= 5.3.0"
  },
  "scripts": {
    "build": "ng build -prod -aot && gulp",
    "start": "ng serve",
    "start:https": "ng serve --ssl true --ssl-key ./dev_cert.key --ssl-cert ./dev_cert.crt",
    "test": "ng test --watch false",
    "e2e": "ng e2e",
    "preinstall": "npm install @angular/compiler-cli --save && npm install --save @angular/cli@latest",
    "postinstall": "ng build"
  },
  "private": true,
  "dependencies": {
    "@angular/cli": "^1.4.5",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/compiler-cli": "^4.4.4",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.1.2",
    "core-js": "^2.4.1",
    "express": "^4.15.4",
    "intl": "^1.2.5",
    "node-sass": "^4.5.2",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "@types/sinon": "^2.2.1",
    "codelyzer": "~2.0.0",
    "gulp": "^3.9.1",
    "gulp-htmlmin": "^3.0.0",
    "gulp-replace": "^0.5.4",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.0",
    "sinon": "^2.2.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.2.0"
  }
}
我的文件:

web: node app.js
我可以在本地运行node app.js和我的网站

但在部署到heroku后,我遇到了以下错误:

Counting objects: 105, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (101/101), done.
Writing objects: 100% (105/105), 382.45 KiB | 5.54 MiB/s, done.
Total 105 (delta 22), 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:        NPM_CONFIG_PRODUCTION=true
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  >= 8.5.0
remote:        engines.npm (package.json):   >= 5.3.0
remote:
remote:        Resolving node version >= 8.5.0...
remote:        Downloading and installing node 8.6.0...
remote:        Bootstrapping npm >= 5.3.0 (replacing 5.3.0)...
remote:        npm 5.4.2 installed
remote:
remote: -----> Restoring cache
remote:        Skipping cache restore (not-found)
remote:
remote: -----> Building dependencies
remote:        Installing node modules (package.json + package-lock)
remote:
remote:        > angular-simple-shopping-cart@1.0.0 preinstall /tmp/build_bcf770b36cce98e184bb462a78de0819
remote:        > npm install @angular/compiler-cli --save && npm install --save @angular/cli@latest
remote:
remote:
remote:        > node-sass@4.5.3 install /tmp/build_bcf770b36cce98e184bb462a78de0819/node_modules/@angular/cli/node_modules/node-sass
remote:        > node scripts/install.js
remote:
remote:        Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.3/linux-x64-57_binding.node
remote:        Download complete
remote:        Binary saved to /tmp/build_bcf770b36cce98e184bb462a78de0819/node_modules/@angular/cli/node_modules/node-sass/vendor/linux-x64-57/binding.node
remote:        Caching binary to /app/.npm/node-sass/4.5.3/linux-x64-57_binding.node
remote:
remote:        > uglifyjs-webpack-plugin@0.4.6 postinstall /tmp/build_bcf770b36cce98e184bb462a78de0819/node_modules/uglifyjs-webpack-plugin
remote:        > node lib/post_install.js
remote:
remote:
remote:        > node-sass@4.5.3 postinstall /tmp/build_bcf770b36cce98e184bb462a78de0819/node_modules/@angular/cli/node_modules/node-sass
remote:        > node scripts/build.js
remote:
remote:        Binary found at /tmp/build_bcf770b36cce98e184bb462a78de0819/node_modules/@angular/cli/node_modules/node-sass/vendor/linux-x64-57/binding.node
remote:        Testing binary
remote:        Binary is fine
remote:        + @angular/compiler-cli@4.4.4
remote:        added 792 packages in 17.707s
remote:        + @angular/cli@1.4.5
remote:        added 114 packages and updated 2 packages in 13.899s
remote:
remote:        > node-sass@4.5.3 install /tmp/build_bcf770b36cce98e184bb462a78de0819/node_modules/node-sass
remote:        > node scripts/install.js
remote:
remote:        Cached binary found at /app/.npm/node-sass/4.5.3/linux-x64-57_binding.node
remote:
remote:        > node-sass@4.5.3 postinstall /tmp/build_bcf770b36cce98e184bb462a78de0819/node_modules/node-sass
remote:        > node scripts/build.js
remote:
remote:        Binary found at /tmp/build_bcf770b36cce98e184bb462a78de0819/node_modules/node-sass/vendor/linux-x64-57/binding.node
remote:        Testing binary
remote:        Binary is fine
remote:
remote:        > angular-simple-shopping-cart@1.0.0 postinstall /tmp/build_bcf770b36cce98e184bb462a78de0819
remote:        > ng build
remote:
remote:        Versions of @angular/compiler-cli and typescript could not be determined.
remote:        The most common reason for this is a broken npm install.
remote:
remote:        Please make sure your package.json contains both @angular/compiler-cli and typescript in
remote:        devDependencies, then delete node_modules and package-lock.json (if you have one) and
remote:        run npm install again.
remote:        npm ERR! code ELIFECYCLE
remote:        npm ERR! errno 2
remote:        npm ERR! angular-simple-shopping-cart@1.0.0 postinstall: `ng build`
remote:        npm ERR! Exit status 2
remote:        npm ERR!
remote:        npm ERR! Failed at the angular-simple-shopping-cart@1.0.0 postinstall script.
remote:        npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote:        npm ERR! A complete log of this run can be found in:
remote:        npm ERR!     /app/.npm/_logs/2017-10-09T09_45_47_273Z-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:        - Dangerous semver range (>) in engines.node
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 phuongshop86.
remote:
To https://git.heroku.com/phuongshop86.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/phuongshop86.git'
请帮我解决这个问题。我尝试了谷歌的很多解决方案,但都不管用

谢谢并致以最良好的问候


Jame

默认情况下,Heroku只安装dependencies对象中列出的软件包,而忽略devDependencies中列出的软件包。将typescript写入依赖项部分,您不需要预安装脚本。

如上所述,默认情况下,heroku不安装开发依赖项。有两种方法可以解决这个问题

  • 将所需的依赖项从
    devDependencies
    添加到
    dependencies
  • 向heroku添加一个环境变量,该变量将允许安装所有开发人员依赖项

    $heroku config:set NPM\u config\u PRODUCTION=false


  • 然而,Heroku更希望您使用第一种方法,因为我们可能不希望安装所有的开发依赖项

    默认情况下,Heroku只安装依赖项对象中列出的软件包,而将忽略devdependences中的软件包。将typescript写入依赖项部分,您不需要预安装脚本。谢谢,它可以工作,然后我将其作为一个答案来编写