我能够成功为React应用构建并运行docker映像,还能够使用“ eb local run”在本地测试容器而没有任何错误,但是似乎无法将应用部署到AWS Elasticbeanstalk。
发生错误的行在下面
rimraf dist && cross-env NODE_ENV =生产webpack --progress --config webpack.config.prod.js
,带有错误日志,提示它无法加载webpack配置文件。
LoadConfigError:无法将未定义或null转换为对象
但是我敢肯定Dockerfile已经将webpack.config.prod.js复制到了容器的目录中
目录
d3-react
- static (folder containing react componentes, including /dist folder and index.html, index.jsx)
- tools
- server.js (script to start express server)
- Dockerfile
- Dockerrun.aws.json
- package.json
- webpack.config.prod.js
Dockerfile
FROM mhart/alpine-node:6
RUN apk add --update bash && rm -rf /var/cache/apk/*
RUN mkdir -p /home/ubuntu/d3-react
WORKDIR /home/ubuntu/d3-react
ENV PATH /home/ubuntu/d3-react/node_modules/.bin:$PATH
COPY package.json /home/ubuntu/d3-react/package.json
RUN npm install --silent
COPY . /home/ubuntu/d3-react
RUN npm run build
VOLUME [".:/home/ubuntu/d3-react/", "/home/ubuntu/d3-react/node_modules"]
EXPOSE 3000
CMD ["npm", "run", "start"]
Dockerrun.aws.json 环境变量分别存储在.ebextensions / .config
中{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "997849770688.dkr.ecr.ap-southeast-1.amazonaws.com/d3-react-frontend-copy_client:latest"
},
"MemoryReservation": 512
}
/var/log/eb-activity.log
[0mThe command '/bin/sh -c npm run build' returned a non-zero code: 1 Failed to build Docker image aws_beanstalk/staging-app, retrying... Sending build context to Docker daemon 366.1kB
Step 1/10 : FROM mhart/alpine-node:6 ---> 17b27e78e1d9 Step 2/10 : RUN apk add --update bash && rm -rf /var/cache/apk/* ---> Using cache ---> 788ef336050d Step 3/10 : WORKDIR /home/ubuntu/d3-react ---> Using cache ---> 33c9e8d293ac Step 4/10 : ENV PATH /home/ubuntu/d3-react/node_modules/.bin:$PATH ---> Using cache ---> 736769aabb8c Step 5/10 : COPY . /home/ubuntu/d3-react ---> Using cache ---> d1d5160f1c90 Step 6/10 : RUN npm install --silent ---> Using cache ---> d02d9d19aa02 Step 7/10 : VOLUME [".:/home/ubuntu/d3-react/", "/home/ubuntu/d3-react/node_modules"] ---> Using cache ---> 9f640d61ad5e Step 8/10 : EXPOSE 3000 ---> Using cache ---> 4c5570b644c9 Step 9/10 : RUN npm run build ---> Running in 8c43fc5e484b
> F1-React-App@1.0.0 build /home/ubuntu/d3-react
> rimraf dist && cross-env NODE_ENV=production webpack --progress --config webpack.config.prod.js
[91m✖ 「config」: An error occurred while trying to load /home/ubuntu/d3-react/webpack.config.prod.js
Did you forget to specify a --require? [0m[91m/home/ubuntu/d3-react/node_modules/@webpack-contrib/config-loader/lib/load.js:85
throw new LoadConfigError(e, configPath);
^ [0m[91m LoadConfigError: Cannot convert undefined or null to object
at Object.<anonymous> (/home/ubuntu/d3-react/webpack.config.prod.js:10:24)
at Module._compile (/home/ubuntu/d3-react/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (/home/ubuntu/d3-react/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at module.exports.moduleId (/home/ubuntu/d3-react/node_modules/import-fresh/index.js:28:9)
at loadJs (/home/ubuntu/d3-react/node_modules/cosmiconfig/dist/loaders.js:9:18)[0m[91m [0m[91m [0m[91mnpm[0m[91m [0m[91mERR![0m[91m Linux
4.14.77-69.57.amzn1.x86_64 [0m[91mnpm[0m[91m [0m[91mERR![0m[91m [0m[91margv[0m[91m "/usr/bin/node" "/usr/bin/npm" "run" "build" [0m[91mnpm[0m[91m [0m[91mERR![0m[91m [0m[91mnode[0m[91m v6.14.4 [0m[91mnpm[0m[91m [0m[91mERR![0m[91m [0m[91mnpm [0m[91m v3.10.10 [0m[91mnpm[0m[91m [0m[91mERR![0m[91m [0m[91mcode[0m[91m ELIFECYCLE [0m[91mnpm[0m[91m [0m[91mERR![0m[91m F1-React-App@1.0.0 build: `rimraf dist && cross-env NODE_ENV=production webpack --progress --config webpack.config.prod.js` [0m[91mnpm[0m[91m [0m[91mERR![0m[91m Exit status 1
编辑:
如果我删除rimraf和cross-env命令,则会看到此错误:
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/ubuntu/d3-react/node_modules/.bin/webpack:5:24)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)[0m[91m
[0m[91mnpm[0m[91m [0m[91mERR![0m[91m [0m[91margv[0m[91m "/usr/bin/node" "/usr/bin/npm" "run" "build"
是什么导致“ npm run build”无法成功完成?