[英]Error: Cannot find module '/next', docker, next.js
I want to create containers out of my next.js
application however I encounter a weird error that I couldn't solve after about 3 days of investigating.我想从我的
next.js
应用程序中创建容器,但是我遇到了一个奇怪的错误,经过大约 3 天的调查后我无法解决。
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" ]
When I run the command docker build -tx/y:tag.
当我运行命令
docker build -tx/y:tag.
it creates the image successfully.它成功创建了图像。 however, when I want to run the container it gives me this error:
但是,当我想运行容器时,它给了我这个错误:
$ 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: []
}
You could try你可以试试
CMD [ "npm", "run", "dev" ]
Hope this helps.希望这可以帮助。
-Try turning off your antivirus (sometimes it blocks normal package updates); -尝试关闭您的防病毒软件(有时它会阻止正常的 package 更新); -Check the changes in package.json;
-检查package.json的变化; -npm update -npm audit fix
-npm 更新 -npm 审计修复
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.