前提・実現したいこと
簡易なreactアプリケーションをcreate-react-appを使わず、webpack
で作成しています。
このアプリをDocker
上で起動できるようにしたのですが、以下のエラーが出て失敗します。
発生している問題・エラーメッセージ
command
1~/hospital master* 2❯ docker-compose up 3Starting hospital_client_1 ... done 4Attaching to hospital_client_1 5client_1 | 6client_1 | > client@1.0.0 start /app 7client_1 | > webpack-dev-server --mode=development "0.0.0.0" "3000" 8client_1 | 9client_1 | /app/node_modules/webpack-cli/bin/utils/convert-argv.js:547 10client_1 | const i = content.indexOf("="); 11client_1 | ^ 12client_1 | 13client_1 | TypeError: content.indexOf is not a function 14client_1 | at /app/node_modules/webpack-cli/bin/utils/convert-argv.js:547:23 15client_1 | at Array.forEach (<anonymous>) 16client_1 | at processOptions (/app/node_modules/webpack-cli/bin/utils/convert-argv.js:546:11) 17client_1 | at processConfiguredOptions (/app/node_modules/webpack-cli/bin/utils/convert-argv.js:170:4) 18client_1 | at module.exports (/app/node_modules/webpack-cli/bin/utils/convert-argv.js:131:10) 19client_1 | at Object.<anonymous> (/app/node_modules/webpack-dev-server/bin/webpack-dev-server.js:84:40) 20client_1 | at Module._compile (internal/modules/cjs/loader.js:777:30) 21client_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10) 22client_1 | at Module.load (internal/modules/cjs/loader.js:643:32) 23client_1 | at Function.Module._load (internal/modules/cjs/loader.js:556:12) 24client_1 | npm ERR! code ELIFECYCLE 25client_1 | npm ERR! errno 1 26client_1 | npm ERR! client@1.0.0 start: `webpack-dev-server --mode=development "0.0.0.0" "3000"` 27client_1 | npm ERR! Exit status 1 28client_1 | npm ERR! 29client_1 | npm ERR! Failed at the client@1.0.0 start script. 30client_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 31client_1 | 32client_1 | npm ERR! A complete log of this run can be found in: 33client_1 | npm ERR! /root/.npm/_logs/2019-12-02T13_52_45_192Z-debug.log 34hospital_client_1 exited with code 1
該当のソースコード
hospital ├ client │ ├ src │ │ ├ components │ │ │ └ Demo.tsx │ │ ├ App.tsx │ │ ├ index.html │ │ └ index.tsx │ ├ Dockerfile │ ├ package.json │ └ webpack.config.js └ docker-compose.yml
Dockerfile
Dockerfile
1FROM node:alpine 2WORKDIR '/app' 3COPY ./package.json ./ 4RUN npm install 5COPY . . 6EXPOSE 3000 7RUN npm start
docker-compose.yml
yml
1version: '3' 2services: 3 client: 4 command: 'npm start --host 0.0.0.0 --port 3000' 5 build: 6 dockerfile: Dockerfile 7 context: ./client 8 ports: 9 - '3000:3000' 10 volumes: 11 - /app/node_modules 12 - ./client:/app
webpack.config.js
js
1const path = require('path'); 2const HtmlWebpackPlugin = require('html-webpack-plugin'); 3 4module.exports = { 5 mode: 'development', 6 7 entry: './src/index.tsx', 8 output: { 9 path: path.resolve(__dirname, 'dist'), 10 filename: 'bundle.js', 11 }, 12 13 devServer: { 14 port: '3000', 15 hot: true, 16 open: true, 17 }, 18 module: { 19 rules: [ 20 { 21 test: /.js(x?)$/, 22 loader: 'babel-loader', 23 exclude: /node_modules/, 24 }, 25 { 26 test: /.ts(x?)$/, 27 loader: 'ts-loader', 28 exclude: /node_modules/, 29 }, 30 ], 31 }, 32 plugins: [ 33 new HtmlWebpackPlugin({ 34 template: './src/index.html', 35 }), 36 ], 37 38 resolve: { 39 extensions: ['.js', '.ts', '.tsx'], 40 }, 41};
package.json
json
1 "scripts": { 2 "test": "echo \"Error: no test specified\" && exit 1", 3 "dev": "webpack-dev-server", 4 "start": "webpack-dev-server --mode=development" 5 },
ソースコード全体は以下にあります。
https://github.com/jpskgc/hospital
試したこと
ローカル環境では問題なくnpm start
で起動します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。