【问题标题】:I have an issue with building react app and webpack using Dockerfile我在使用 Dockerfile 构建反应应用程序和 webpack 时遇到问题
【发布时间】:2019-05-16 17:17:43
【问题描述】:

我正在使用 webpack 准备一个带有内置反应应用程序的 Docker 映像。我可能错过了一些东西,因为在执行yarn build 之后我收到一个关于缺少 webpack 的错误。但我在node_modules/.bin/webpack 中有webpack,它是使用COPY . /web 复制的

$ webpack --mode production
/bin/sh: webpack: not found
error Command failed with exit code 127.

我尝试只运行yarn,但这显然不会构建应用程序,但我检查了容器以确认文件复制。

package.json

{
  "name": "@mySweetApp/my-app",
  "version": "0.0.1",
  "description": "My Swee App",
  "main": "./src/index.js",
  "private": true,
  "license": "MIT",
  "scripts": {
    "build": "webpack --mode production",
    "start": "webpack-dev-server --mode development --open --hot"
  },

Dockerfile

FROM node:12.2.0-alpine as node

RUN mkdir -p /web

WORKDIR /web

#Copy dependency definition
COPY package.json /web

RUN yarn install

#Copy all files
COPY . /web

RUN yarn build

文件树(删除不需要的东西)

  },├── .babelrc
├── docker
│   ├── default.conf
│   ├── .dockerignore
│   └── ssl
├── Dockerfile
├── node_modules
│   ├── @babel
│   ├── babel-core
│   ├── .bin
│   │   ├── eslint -> ../../../../node_modules/eslint/bin/eslint.js
│   │   ├── eslint-config-prettier-check -> ../../../../node_modules/eslint-config-prettier/bin/cli.js
│   │   ├── lingui -> ../../../../node_modules/@lingui/cli/lingui.js
│   │   ├── lint-staged -> ../../../../node_modules/lint-staged/index.js
│   │   ├── webpack -> ../../../../node_modules/webpack/bin/webpack.js
│   │   ├── webpack-cli -> ../../../../node_modules/webpack-cli/bin/cli.js
│   │   └── webpack-dev-server -> ../../../../node_modules/webpack-dev-server/bin/webpack-dev-server.js
│   ├── .cache
│   ├── debug
│   ├── jsesc
│   ├── ms
│   └── source-map
├── package.json
├── src
└── webpack.config.js

我确实错过了这里的一些小东西,你能帮帮我吗?

【问题讨论】:

    标签: webpack dockerfile yarnpkg


    【解决方案1】:

    我可能解决了这个问题,我注意到那些符号链接指向父目录。我必须将 dockerfile 移动到不同的目录并将更多文件复制到图像。 如果有任何成功,我会更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 2019-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多