Heroku部署错误:找不到模块-编译 [英] Heroku deploy Error: Cannot find module - compilation
问题描述
这与其他问题类似,但我将解释有什么不同。
This is similar to other questions, but I'll explain what's different.
与其他许多问题一样,我有一个可以在自己的服务器上正常运行的应用,但是当我推送到Heroku时,出现以下错误:
Like the many others, I have an app that works fine on my own server, but when I push to Heroku, I get the following error:
remote: > react-scripts build
remote:
remote: module.js:549
remote: throw err;
remote: ^
remote:
remote: Error: Cannot find module './error'
remote: at Function.Module._resolveFilename (module.js:547:15)
remote: at Function.Module._load (module.js:474:25)
remote: at Module.require (module.js:596:17)
remote: at require (internal/module.js:11:18)
remote: at Object.<anonymous> (/tmp/build_96886a1c0acbba91a1be57ec9c1487e8/client/node_modules/browserslist/index.js:7:25)
remote: at Module._compile (module.js:652:30)
remote: at Object.Module._extensions..js (module.js:663:10)
remote: at Module.load (module.js:565:32)
remote: at tryModuleLoad (module.js:505:12)
remote: at Function.Module._load (module.js:497:3)
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! client@0.1.0 build: `react-scripts build`
区别是我没有 require('./ error')
或安装的文件或文件夹或依赖项称为错误。
The difference, is I have no require('./error')
or file or folder or dependency installed called error.
我尝试了以下操作:
1。
npm install -g
npm install -g
2。
删除node_modules
Delete node_modules
npm缓存清理--force
npm cache clean --force
npm install
npm install
3。
添加到我的package.json中:
3. Added to my package.json:
"engines": {
"node": "8.11.3"
}
4。
从零开始,我克隆了我的工作应用程序,创建了一个新的Heroku实例,并尝试进行部署。
4. Three times from scratch I cloned my working app, created a new Heroku instance, and tried to deploy.
5。
试过这个:
5. Tried this:
heroku config:set NODE_MODULES_CACHE = false
heroku config:set NODE_MODULES_CACHE=false
这些解决方案和其他无效的方法来自这些帖子:
These solutions and others that didn't work came from these posts:
Heroku部署错误:部署后无法运行Node App:找不到模块'/app/web.js'
Heroku部署错误:无法查找模块'./errors/cast'
https://github.com/nodejs/help/issues/1271
https://help.heroku.com/TO64O3OG/cannot -find-module-in-node-js-run-time
推荐答案
好吧,事实证明答案可以在Heroku的对Node.js部署进行故障排除页面。事实证明,我有时不小心开始跟踪node_modules。我不记得它是如何发生的,但是认为它是在我愚弄自己的.gitignore时发生的。直接从疑难解答页面获得的解决方案是:
Well, it turns out the answer can be found in Heroku's Troubleshooting Node.js Deploys page. It turned out that I had at some point accidentally started tracking node_modules. I can't remember how it happened, but think it happened at one point when I was fooling with my .gitignore. This solution, straight from the troubleshooting page was:
-
检查以查看是否正在跟踪node_modules-如果返回的是列表结果,您是:
Check to see if you are tracking node_modules -- if this returns a list of results, you are:
git ls-files | grep node_modules
确保您不再跟踪它
Ensure you're not tracking it anymore
echo "node_modules" >.gitignore
删除缓存的node_modules
Remove the cached node_modules
git rm -r --cached node_modules
进行新提交
Make a new commit
git commit -am 'untracked node_modules'
这解决了我的问题。
这篇关于Heroku部署错误:找不到模块-编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!