简体   繁体   English

Webpack无法解析Docker映像中的节点模块

[英]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.

相关问题 Webpack 无法解析 JS 模块(在 Typescript 项目中) - Webpack unable to resolve JS module (in Typescript project) 打字稿/节点无法解析模块路径 - Typescript / node unable to resolve module paths 使用Node和Webpack在Heroku上托管-找不到模块,无法解析'./Navbar' - Hosting on Heroku with Node and Webpack — Module not found, can't resolve './Navbar' Docker-无法解析'/ usr / src / app / src'中的节点模块 - Docker - Can't resolve node module in '/usr/src/app/src' 使用 webpack 丑化节点模块 - Uglify node module with webpack 找不到Webpack模块:错误:无法解析模块 - Webpack Module not found: Error: Cannot resolve module Webpack - 找不到模块:错误:无法解析“node_modules\\chokidar\\lib” - Webpack - Module not found: Error: Can't resolve 'node_modules\chokidar\lib' Webpack和TypeScript:无法解析node.d.ts中的模块'child_process' - Webpack and TypeScript: Cannot resolve module 'child_process' in node.d.ts Webpack resolve.fallback 不起作用。 未找到模块:错误:无法解析 node_modules\aws4 中的“加密” - Webpack resolve.fallback not working. Module not found: Error: Can't resolve 'crypto' in node_modules\aws4 在节点(webpack)中找不到模块 - Cannot find module in node (webpack)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM