Node.js 应用程序无法部署到 Heroku

Posted

技术标签:

【中文标题】Node.js 应用程序无法部署到 Heroku【英文标题】:Node.js application fails to deploy to Heroku 【发布时间】:2017-12-05 04:32:48 【问题描述】:

我试图将应用程序部署到 Heroku。应用程序只有在更改引擎版本后才能成功部署。如果我尝试在不修改“引擎”部分的情况下进行部署,则部署会失败并出现以下错误:

remote:        ERROR in ./resources/assets/sass/app.scss
remote:        Module build failed: ModuleBuildError: Module build failed: Error: ENOENT: no such file or directory, scandir '/tmp/build_7b88e5ab3110a2273bdb09b2d4f7c673/node_modules/node-sass/vendor'

这是我的 package.json


  "private": true,
  "name": "instagram",
  "description": "<p align=\"center\"><img src=\"https://laravel.com/assets/img/components/logo-laravel.svg\"></p>",
  "version": "1.0.0",
  "main": "webpack.config.js",
  "directories": 
    "test": "tests"
  ,
  "engines" : 
    "npm" : "5.0.4",
    "node": "7.4.0",
    "yarn": "0.24.6"
  ,
  "author": "",
  "license": "ISC",
  "dependencies": 
    "bootstrap": "^3.3.7",
    "bootstrap-notify": "^3.1.3",
    "bootstrap-sass": "^3.3.7",
    "bootstrap-switch": "^3.3.4",
    "css-loader": "^0.28.4",
    "cssnano": "^3.10.0",
    "extract-text-webpack-plugin": "^2.1.2",
    "file-loader": "^0.11.2",
    "font-awesome": "^4.7.0",
    "jquery": "^3.2.1",
    "knockout": "^3.4.2",
    "node-sass": "^4.5.3",
    "nprogress": "^0.2.0",
    "optimize-css-assets-webpack-plugin": "^2.0.0",
    "sass-loader": "^6.0.6",
    "select2": "^4.0.3",
    "uglifyjs-webpack-plugin": "^0.4.6",
    "url-loader": "^0.5.9",
    "webpack": "^2.2.0",
    "webpack-cleanup-plugin": "^0.5.1"
  ,
  "scripts": 
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  

除了更改引擎版本之外,也许您有任何解决方案?

【问题讨论】:

【参考方案1】:

这是解决这个问题的解决方案:

"scripts": 
  "heroku-postbuild": "yarn add --force node-sass"

或者,对于npm

"scripts": 
  "heroku-postbuild": "npm rebuild node-sass"

见:

https://github.com/sass/node-sass/issues/1387#issuecomment-185451183

和:

https://github.com/rails/webpacker/issues/422#issuecomment-304018204

【讨论】:

【参考方案2】:

我找到了解决方案 - Heroku 上禁用了节点模块缓存:

heroku config:set NODE_MODULES_CACHE=false
$ git commit -am 'disable node_modules cache' --allow-empty
$ git push heroku master

【讨论】:

以上是关于Node.js 应用程序无法部署到 Heroku的主要内容,如果未能解决你的问题,请参考以下文章

Heroku 部署 - “推送被拒绝,无法编译 Node.js 应用程序”

Node.js MEAN Stack App 在本地工作,但无法部署到 Heroku

Node.js Heroku 部署 - 无法执行安装后脚本来安装 Bower

将 Node.js 应用程序部署到 Heroku 的应用程序错误

Heroku 构建失败 - 推送被拒绝,无法编译 node.js 应用程序,无法缩小包,许多错误

heroku push 被拒绝,无法编译 Node.js 应用程序