错误:找不到模块“ /next”、docker、next.js

时间:2020-06-24 09:31:10

标签: node.js reactjs docker containers next.js

我想从我的next.js应用程序中创建容器,但是经过大约三天的调查,我遇到了一个无法解决的怪异错误。

package.json:

{
  "name": "client",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "next",
  },
  "keywords": [],
  "author": "Shahin Ghasemi",
  "license": "ISC",
  "dependencies": {
    "next": "^9.4.4",
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  }
}

Dockerfile:

FROM node:alpine
COPY package.json .
RUN npm install
CMD [ "next", "run","dev" ]

当我运行命令docker build -t x/y:tag .时,它会成功创建图像。但是,当我想运行容器时,会出现以下错误:

$ docker run  abbe27e7cc4d
internal/modules/cjs/loader.js:1023
  throw err;
  ^
Error: Cannot find module '/next'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1020:15)
at Function.Module._load (internal/modules/cjs/loader.js:890:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

2 个答案:

答案 0 :(得分:0)

您可以尝试

<Logo width={120} height={40} fill={"any color, will fallback to #000"} />

希望这会有所帮助。

答案 1 :(得分:0)

-尝试关闭防病毒软件(有时会阻止正常的软件包更新); -检查package.json中的更改; -npm更新 -npm审核修复程序