簡體   English   中英

錯誤:在Heroku中加載Express時找不到模塊“ ./layer”

[英]Error: Cannot find module './layer' when loading Express in Heroku

我目前正在Heroku上構建Node.js Express應用程序。 它在本地工作正常,但是當我將其上傳到Heroku時,出現以下錯誤:

2016-09-09T14:14:46.606481+00:00 app[web.1]: [DEBUG] Loading modules...
2016-09-09T14:14:46.607904+00:00 app[web.1]: [DEBUG] Loading express...
2016-09-09T14:14:46.632062+00:00 app[web.1]: module.js:457
2016-09-09T14:14:46.632064+00:00 app[web.1]:     throw err;
2016-09-09T14:14:46.632065+00:00 app[web.1]:     ^
2016-09-09T14:14:46.632065+00:00 app[web.1]:
2016-09-09T14:14:46.632066+00:00 app[web.1]: Error: Cannot find module './layer'

當我去查看本地node_modules時,會出現文件node_modules\\express\\lib\\router\\layer.js

然后,我運行heroku run bash並看到:

~/node_modules/express/lib/router $ ls
index.js  route.js

所以我跑:

~ $ rm -rf node_modules/
~ $ npm i
~ $ npm start

而且一切正常。 但是注銷heroku bash並停止工作。 之后,如果我重新登錄並運行npm start ,它將再次失敗,並顯示第一條消息:

Running bash on little-owl... up, run.6609
~ $ npm start

> little-owl@0.0.1 start /app
> node server.js

[DEBUG] Loading modules...
[DEBUG] Loading express...
module.js:457
    throw err;
    ^

Error: Cannot find module './layer'

有任何想法嗎?

Heroku不是VPS。 heroku run bash ,您不會對應用程序的文件系統進行任何永久更改。 當您進行部署時,一切都在構建時完成。

從這里的症狀看,您的應用node_modules在過去的某個時間已經簽入了一些不完整的node_modules 因此,首先,從git中刪除node_modules

$ echo 'node_modules' >> .gitignore
$ git rm -r --cached node_modules
$ git commit -am 'ignore node_modules'

然后,禁用應用程序的緩存並推送:

$ heroku config:set NODE_MODULES_CACHE=false
$ git push heroku master

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM