Heroku 构建失败:“node_modules 已签入源代码管理”

Posted

技术标签:

【中文标题】Heroku 构建失败:“node_modules 已签入源代码管理”【英文标题】:Heroku Build Failed: "node_modules checked into source control" 【发布时间】:2016-03-21 12:51:15 【问题描述】:

我正在 Heroku 上部署一个基于 MEAN 堆栈的网站。在解决问题时,我从我的 .gitignore 文件中删除了 node_modules/,自从我的应用程序出现“构建失败”错误以来。

我已将 node_modules/ 读取到文件中,但似乎损坏已经造成,因为构建仍然失败。

日志中建议的可能问题之一是: "- node_modules 签入源代码管理"

我该如何撤消我所做的事情?

 -----> Deleting 1 files matching .slugignore patterns.
 -----> Using set buildpack heroku/nodejs
 -----> Node.js app detected
 -----> Creating runtime environment

   NPM_CONFIG_LOGLEVEL=error
   NPM_CONFIG_PRODUCTION=true
   NODE_ENV=production
   NODE_MODULES_CACHE=true
 -----> Installing binaries
   engines.node (package.json):  0.10.x
   engines.npm (package.json):   2.x.x

   Resolving node version 0.10.x via semver.io...
   Downloading and installing node 0.10.41...
   Resolving npm version 2.x.x via semver.io...
   Downloading and installing npm 2.14.15 (replacing version 1.4.29)...
   npm WARN deprecated This version of npm lacks support for important features,
   npm WARN deprecated such as scoped packages, offered by the primary npm
   npm WARN deprecated registry. Consider upgrading to at least npm@2, if not the
   npm WARN deprecated latest stable version. To upgrade to npm@2, run:
   npm WARN deprecated
   npm WARN deprecated   npm -g install npm@latest-2
   npm WARN deprecated
   npm WARN deprecated To upgrade to the latest stable version, run:
   npm WARN deprecated
   npm WARN deprecated   npm -g install npm@latest
   npm WARN deprecated
   npm WARN deprecated (Depending on how Node.js was installed on your system, you
   npm WARN deprecated may need to prefix the preceding commands with `sudo`, or if
   npm WARN deprecated on Windows, run them from an Administrator prompt.)
   npm WARN deprecated
   npm WARN deprecated If you're running the version of npm bundled with
   npm WARN deprecated Node.js 0.10 LTS, be aware that the next version of 0.10 LTS
   npm WARN deprecated will be bundled with a version of npm@2, which has some small
   npm WARN deprecated backwards-incompatible changes made to `npm run-script` and
   npm WARN deprecated semver behavior.
 -----> Restoring cache
   Loading 2 from cacheDirectories (default):
   - node_modules (exists - skipping)
   - bower_components (not cached - skipping)
 -----> Building dependencies
   Prebuild detected (node_modules already exists)
   Rebuilding any native modules

   > bson@0.2.22 install /tmp/build_###########/node_modules/connect-mongo/node_modules/bson
   > (node-gyp rebuild 2> builderror.log) || (exit 0)

   make: Entering directory `/tmp/build_###########/node_modules/connect-mongo/node_modules/bson/build'
   CXX(target) Release/obj.target/bson/ext/bson.o
   SOLINK_MODULE(target) Release/obj.target/bson.node
   COPY Release/bson.node
   make: Leaving directory `/tmp/build_###########/node_modules/connect-mongo/node_modules/bson/build'

   > bson@0.2.22 install /tmp/build_###########/node_modules/connect-mongo/node_modules/bson
   > (node-gyp rebuild 2> builderror.log) || (exit 0)

   make: Entering directory `/tmp/build_###########/node_modules/connect-mongo/node_modules/bson/build'
   CXX(target) Release/obj.target/bson/ext/bson.o
   SOLINK_MODULE(target) Release/obj.target/bson.node
   COPY Release/bson.node
   make: Leaving directory `/tmp/build_###########/node_modules/connect-mongo/node_modules/bson/build'

   > bson@0.2.22 install /tmp/build_###########/node_modules/mongoose/node_modules/mongodb/node_modules/bson
   > (node-gyp rebuild 2> builderror.log) || (exit 0)

   make: Entering directory `/tmp/build_###########/node_modules/mongoose/node_modules/mongodb/node_modules/bson/build'
   CXX(target) Release/obj.target/bson/ext/bson.o
   SOLINK_MODULE(target) Release/obj.target/bson.node
   COPY Release/bson.node
   make: Leaving directory `/tmp/build_###########/node_modules/mongoose/node_modules/mongodb/node_modules/bson/build'

   > phantomjs@1.9.19 install /tmp/build_###########/node_modules/phantomjs
   > node install.js

   PhantomJS not found on PATH
   Downloading https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
   Saving to /tmp/phantomjs/phantomjs-1.9.8-linux-x86_64.tar.bz2
   Receiving...

   Received 12854K total.
   Extracting tar contents (via spawned process)
   Removing /tmp/build_###########/node_modules/phantomjs/lib/phantom
   Copying extracted folder /tmp/phantomjs/phantomjs-1.9.8-linux-x86_64.tar.bz2-extract-1450118671217/phantomjs-1.9.8-linux-x86_64 -> /tmp/build_###########/node_modules/phantomjs/lib/phantom
   Writing location.js file
   Done. Phantomjs binary available at /tmp/build_###########/node_modules/phantomjs/lib/phantom/bin/phantomjs

   > kerberos@0.0.11 install /tmp/build_###########/node_modules/kerberos
   > (node-gyp rebuild 2> builderror.log) || (exit 0)

   make: Entering directory `/tmp/build_###########/node_modules/kerberos/build'
   CXX(target) Release/obj.target/kerberos/lib/kerberos.o
   CXX(target) Release/obj.target/kerberos/lib/worker.o
   CC(target) Release/obj.target/kerberos/lib/kerberosgss.o
   CC(target) Release/obj.target/kerberos/lib/base64.o
   CXX(target) Release/obj.target/kerberos/lib/kerberos_context.o
   SOLINK_MODULE(target) Release/obj.target/kerberos.node
   COPY Release/kerberos.node
   make: Leaving directory `/tmp/build_###########/node_modules/kerberos/build'

   > ws@0.4.32 install /tmp/build_###########/node_modules/ws
   > (node-gyp rebuild 2> builderror.log) || (exit 0)

   make: Entering directory `/tmp/build_###########/node_modules/ws/build'
   CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
   SOLINK_MODULE(target) Release/obj.target/bufferutil.node
   COPY Release/bufferutil.node
   CXX(target) Release/obj.target/validation/src/validation.o
   SOLINK_MODULE(target) Release/obj.target/validation.node
   COPY Release/validation.node
   make: Leaving directory `/tmp/build_###########/node_modules/ws/build'

   > v8-profiler@5.2.12 preinstall /tmp/build_###########/node_modules/v8-profiler
   >


   > v8-profiler@5.2.12 install /tmp/build_###########/node_modules/v8-profiler
   > node-pre-gyp install --fallback-to-build

   sh: 1: node-pre-gyp: Permission denied

   npm ERR! Linux 3.13.0-71-generic
   npm ERR! argv "node" "/tmp/build_###########/.heroku/node/bin/npm" "rebuild"
   npm ERR! node v0.10.41
   npm ERR! npm  v2.14.15
   npm ERR! code ELIFECYCLE
   npm ERR! v8-profiler@5.2.12 install: `node-pre-gyp install --fallback-to-build`
   npm ERR! Exit status 126
   npm ERR!
   npm ERR! Failed at the v8-profiler@5.2.12 install script 'node-pre-gyp install --fallback-to-build'.
   npm ERR! This is most likely a problem with the v8-profiler package,
   npm ERR! not with npm itself.
   npm ERR! Tell the author that this fails on your system:
   npm ERR!     node-pre-gyp install --fallback-to-build
   npm ERR! You can get their info via:
   npm ERR!     npm owner ls v8-profiler
   npm ERR! There is likely additional logging output above.

   npm ERR! Please include the following file with any support request:
   npm ERR!     /tmp/build_###########/npm-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

   Some possible problems:

   - node_modules checked into source control
   https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git

   Love,
   Heroku

  !     Push rejected, failed to compile Node.js app

【问题讨论】:

【参考方案1】:

尽管您已将node_modules 重新添加到您的.gitignore,但正如您所说,损害已经造成。所以你需要从你的 git repo 中删除 node_modules 。试试这个:

git rm -r --cached node_modules
git commit -m 'Remove node_modules'

第一个命令从 git 存储库中递归删除 node_modules 而不删除您的本地文件,第二个命令提交删除。

然后您可以将更改推送到 Heroku。

【讨论】:

感谢您和 OP!没有意识到 node_modules 不应该在那里,直到现在它都构建得很好......

以上是关于Heroku 构建失败:“node_modules 已签入源代码管理”的主要内容,如果未能解决你的问题,请参考以下文章

Heroku 在 uglifier 上构建失败

Discord.js 机器人的 Heroku 构建失败

Heroku 构建依赖项安装失败

我的 Heroku 构建一直失败,我不知道为啥

尝试将带有顺风的 MERN 堆栈部署到 Heroku 时构建失败

在 Heroku 部署中构建失败