[英]webpack unable to resolve node module in docker image
#Dockerfile
FROM node:alpine
RUN mkdir /morty
ADD . /morty/
WORKDIR /morty/
RUN yarn cache clean && yarn install
RUN ls node_modules | grep autosuggest
RUN find /morty/node_modules/react-autosuggest -ls
CMD npm run dev
This builds as expected, but as soon as I request a page from the dev server, I get an error 这将按预期进行构建,但是一旦我从开发服务器请求页面,就会收到错误消息
ERROR in ./src/components/molecules/AutoSuggest/index.js
web_1 | Module not found: Error: Can't resolve 'react-autosuggest' in '/morty/src/components/molecules/AutoSuggest'
web_1 | @
which would suggest to me that for some reason, the react-autosuggest
module was not installed; 这会向我暗示由于某种原因,没有安装
react-autosuggest
模块; however, the output of step 6 & 7 in my Dockerfile
seems to invalidate that hypothesis. 但是,我的
Dockerfile
中第6步和第7步的输出似乎使该假设无效。
Step 6/7 : RUN ls node_modules | grep autosuggest
---> Running in 0c87c4318a6f
react-autosuggest
Step 7/9 : RUN find /morty/node_modules/react-autosuggest -ls
---> Running in 498c6b9080c7
12042711 4 drwxr-xr-x 3 root root 4096 Mar 6 16:40 /morty/node_modules/react-autosuggest
12042729 4 drwxr-xr-x 3 root root 4096 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist
521128 4 -rw-r--r-- 1 root root 1735 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/theme.js
12042731 4 drwxr-xr-x 2 root root 4096 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/standalone
521127 36 -rw-r--r-- 1 root root 33193 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/standalone/autosuggest.min.js
521126 112 -rw-r--r-- 1 root root 113248 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/standalone/autosuggest.js
521123 28 -rw-r--r-- 1 root root 27217 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/Autosuggest.js
521124 4 -rw-r--r-- 1 root root 65 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/index.js
521121 24 -rw-r--r-- 1 root root 24423 Mar 6 16:40 /morty/node_modules/react-autosuggest/README.md
521129 8 -rw-r--r-- 1 root root 4195 Mar 6 16:40 /morty/node_modules/react-autosuggest/package.json
521120 4 -rw-r--r-- 1 root root 1088 Mar 6 16:40 /morty/node_modules/react-autosuggest/LICENSE
package.json
does contain the entry "react-autosuggest": "^9.3.4",
in dependencies
and the app performs as expected in its un-containerized form. package.json
确实在dependencies
项中包含条目"react-autosuggest": "^9.3.4",
并且该应用程序以其未包含容器的形式按预期执行。
also, possibly relevant is that the base config for this project came from the Arc project 同样,可能相关的是该项目的基本配置来自Arc项目
I also faced this issue while trying to build my npm project using a container which had WORKDIR
as a mounted volume. 在尝试使用具有
WORKDIR
作为挂载卷的容器来构建我的npm项目时,我也遇到了这个问题。 I resolved this issue by removing the mounted volume by name. 我通过删除挂载卷的名称解决了此问题。
docker volume ls
to list the volumes docker volume ls
列出卷
DRIVER VOLUME NAME
local myproject_named_volume
docker volume rm -f myproject_named_volume
to remove the volume docker volume rm -f myproject_named_volume
删除卷
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.