gpt4 book ai didi

git - 在 Heroku 上创建 Node.js 应用程序时,我应该将文件夹 "node_modules" checkin Git 吗?

转载 作者:IT老高 更新时间:2023-10-28 21:44:34 29 4
gpt4 key购买 nike

我在这里遵循了关于 Heroku 上 Node.js 的基本入门说明:

https://devcenter.heroku.com/categories/nodejs

这些指令没有告诉你创建一个 .gitignore node_modules,因此暗示文件夹 node_modules 应该被 checkin 到 Git。当我在 Git 存储库中包含 node_modules 时,我的入门应用程序运行正常。

当我遵循更高级的示例时:

它指示我将文件夹 node_modules 添加到文件 .gitignore。所以我从 Git 中删除了文件夹 node_modules,将其添加到文件 .gitignore 中,然后重新部署。这次部署失败如下:

-----> Heroku receiving push
-----> Node.js app detected
-----> Resolving engine versions
Using Node.js version: 0.8.2
Using npm version: 1.0.106
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
Error: npm doesn't work with node v0.8.2
Required: node@0.4 || 0.5 || 0.6
at /tmp/node-npm-5iGk/bin/npm-cli.js:57:23
at Object.<anonymous> (/tmp/node-npm-5iGk/bin/npm-cli.js:77:3)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/tmp/node-npm-5iGk/cli.js:2:1)
at Module._compile (module.js:449:26)
Error: npm doesn't work with node v0.8.2
Required: node@0.4 || 0.5 || 0.6
at /tmp/node-npm-5iGk/bin/npm-cli.js:57:23
at Object.<anonymous> (/tmp/node-npm-5iGk/bin/npm-cli.js:77:3)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/tmp/node-npm-5iGk/cli.js:2:1)
at Module._compile (module.js:449:26)
Dependencies installed
-----> Discovering process types
Procfile declares types -> mongod, redis, web
-----> Compiled slug size is 5.0MB
-----> Launching... done, v9

运行“heroku ps”确认崩溃。好的,没问题,所以我回滚了更改,将文件夹 node_module 添加回 Git 存储库并将其从文件 .gitignore 中删除。但是,即使在还原后,我仍然在部署时收到相同的错误消息,但现在应用程序再次正常运行。运行“heroku ps”告诉我应用程序正在运行。

这样做的正确方法是什么?是否包含文件夹 node_modules?为什么回滚时仍然会收到错误消息?我的猜测是 Git 存储库在 Heroku 方面的状态很差。

最佳答案

第二次更新

常见问题解答不再可用。

来自 shrinkwrap 的文档:

If you wish to lock down the specific bytes included in a package, for example to have 100% confidence in being able to reproduce a deployment or build, then you ought to check your dependencies into source control, or pursue some other mechanism that can verify contents rather than versions.

Shannon 和 Steven 之前提到过这一点,但我认为它应该是公认答案的一部分。


更新

为以下推荐列出的来源has been updated .他们不再建议提交 node_modules 文件夹。

Usually, no. Allow npm to resolve dependencies for your packages.

For packages you deploy, such as websites and apps, you should use npmshrinkwrap to lock down your full dependency tree:

https://docs.npmjs.com/cli/shrinkwrap


原帖

作为引用,npm FAQ 清楚地回答了你的问题:

Check node_modules into git for things you deploy, such as websitesand apps. Do not check node_modules into git for libraries and modulesintended to be reused. Use npm to manage dependencies in your devenvironment, but not in your deployment scripts.

关于这方面的一些好的理由,请阅读 Mikeal Rogers' post on this .


来源:https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git

关于git - 在 Heroku 上创建 Node.js 应用程序时,我应该将文件夹 "node_modules" checkin Git 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11459475/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com