[英]Docker + Nodejs Getting Error: Cannot find module “for a module that I wrote”
[英]using nodejs and forever i get the error Cannot find module
我正試圖永遠啟動所有微服務
所有服務均以相同方式失敗
我的forever.json看起來像(縮寫)
[
{
"uid": "account-service",
"append": true,
"watch": true,
"script": "app.js",
"sourceDir": "/home/trig/account-service/",
"workingDir": "/home/trig/account-service/",
"logFile": "/home/trig/logs/forever.log",
"outFile": "/home/trig/logs/account_service_out.log",
"errFile": "/home/trig/logs/account_service_err.log"
},
開始后我會做
forever list and get (abbreviated)
/home/trig/.forever/lQOi.log STOPPED
如果我看一下日志
data: account-service:25858 - module.js:471
data: account-service:25858 - throw err;
data: account-service:25858 - ^
data: account-service:25858 - Error: Cannot find module '/home/trig/account-service'
data: account-service:25858 - at Function.Module._resolveFilename (module.js:469:15)
data: account-service:25858 - at Function.Module._load (module.js:417:25)
data: account-service:25858 - at Module.runMain (module.js:604:10)
data: account-service:25858 - at run (bootstrap_node.js:383:7)
data: account-service:25858 - at startup (bootstrap_node.js:149:9)
data: account-service:25858 - at bootstrap_node.js:496:3
data: account-service:25858 - error: Forever detected script exited with code: 1
但是如果我這樣做
ls -ls /home/trig/account-service
4 -rw-rw-r-- 1308 Dec 28 20:43 app.js
4 drwxrwxr-x 4096 Dec 28 20:43 controllers
4 drwxrwxr-x 4096 Dec 22 05:36 env
4 drwxrwxr-x 4096 Dec 28 20:43 models
4 drwxrwxr-x 154 4096 Dec 28 20:43 node_modules
4 -rw-rw-r-- 1 359 Dec 28 20:43 package.json
4 drwxrwxr-x 2 4096 Dec 28 20:43 utils
然后,我嘗試將路徑從絕對路徑更改為相對路徑(基於下面的評論)
[
{
"uid": "account-service",
"append": true,
"watch": true,
"script": "app.js",
"sourceDir": "./account-service/",
"workingDir": "./account-service/",
"logFile": "/home/trig/logs/forever.log",
"outFile": "/home/trig/logs/account_service_out.log",
"errFile": "/home/trig/logs/account_service_err.log"
},
然后做了
forever start account-service ./forever.json
仍然看到錯誤
data: account-service:1795 - module.js:471
data: account-service:1795 - throw err;
data: account-service:1795 - ^
data: account-service:1795 - Error: Cannot find module '/home/trig/account-service'
data: account-service:1795 - at Function.Module._resolveFilename (module.js:469:15)
data: account-service:1795 - at Function.Module._load (module.js:417:25)
data: account-service:1795 - at Module.runMain (module.js:604:10)
data: account-service:1795 - at run (bootstrap_node.js:383:7)
data: account-service:1795 - at startup (bootstrap_node.js:149:9)
data: account-service:1795 - at bootstrap_node.js:496:3
data: account-service:1795 - error: Forever detected script exited with code: 1
如果將forever.json文件移動到dir / home / trig / account-service中(並刪除其他服務),並將sourceDir和workingDir保留為絕對路徑,則它將正確啟動
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.