因此,对于我的项目(使用 React 和 Redux),我一直遇到“找不到模块”的错误。我已经在 google 和 stackoverflow 上搜索了几个解决方案,并且看到人们说我的 node_modules 出了问题,所以我删除了它们,并且还 npm install (重新安装)。错误仍然存在,我认为这与我的 webpack.config.js 文件有关......
\n我只是希望构建能够正常工作并且反应元素和组件能够渲染。
\n错误
\nModule not found: Error: Can't resolve './node_modules/react' in '/Users/<user-name>/Documents/gift-test/client'\n\nERROR in ./client/index.js\nModule not found: Error: Can't resolve './node_modules/react' in '/Users/<user-name>/Documents/gift-test/client'\n @ ./client/index.js 1:0-41 15:21-26 17:16-21\n\nERROR in ./client/index.js\nModule not found: Error: Can't resolve './node_modules/react-dom' in '/Users/<user-name>/Documents/gift-test/client'\n @ ./client/index.js 2:0-50 15:0-6\n\nERROR in ./client/index.js\nModule not found: Error: Can't resolve './node_modules/react-redux' in '/Users/<user-name>/Documents/gift-test/client'\n @ ./client/index.js 3:0-54 15:41-49\n\nERROR in ./client/store.js\nModule not found: Error: Can't resolve './node_modules/redux' …Run Code Online (Sandbox Code Playgroud) 我是否必须首先克隆 wait-for-it 存储库并编辑 wait-for-it.sh 文件的部分?
https://github.com/vishnubob/wait-for-it/blob/master/wait-for-it.sh
我试图在我的客户服务连接并运行其服务器后 5 秒后触发我的主文件。(或每当客户服务正确连接服务器时)。
我知道在 Dockerfile 中,我们需要向其中添加这些命令(将文件复制到 workdir,并将 shell 脚本作为可执行文件运行。)
...
COPY wait-for-it.sh .
RUN chmod +x /wait-for-it.sh
...
Run Code Online (Sandbox Code Playgroud)
这是我当前的 Docker-Compose 文件
version: '3'
services:
books:
build: './books'
container_name: "horus-books"
ports:
- "30043:30043"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
customers:
depends_on:
- books
build: './customers'
container_name: "horus-customers"
ports:
- "6000:6000"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
main:
depends_on:
- customers
build: './main'
container_name: "horus-main"
ports:
- "4555:4555"
command: ["./wait-for-it.sh", "customers:6000", "--", "node", "main.js"]
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
Run Code Online (Sandbox Code Playgroud)
主服务Dockerfile
FROM node:12.14.0
WORKDIR /usr/src/app …Run Code Online (Sandbox Code Playgroud)