AWS Elastic Beanstalk - How to Build a JS Package Using npm and webpack

I have a node js application deployed on an elastic stretch. Installed and symbolic links node, npm and webpack. But when you run npm run build-prod , which itself calls the webpack --config /var/app/current/webpack.prod.config.js script webpack --config /var/app/current/webpack.prod.config.js . Getting the next error with exit state -2. The same thing happens if I also run the webpack command. I am looking for solutions.

 [2016-07-26T06:57:36.301Z] INFO [9731] - [Application update app-5c81-160726_122417@24 /AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_site_web/Command 06_npm_run_build_prod] : Activity execution failed, because: > site-web@1.0.0 build-prod /tmp/deployment/application > webpack --config /var/app/current/webpack.prod.config.js npm ERR! Linux 4.4.14-24.50.amzn1.x86_64 npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/node" "/bin/npm" "run" "build-prod" npm ERR! node v4.4.6 npm ERR! npm v2.15.5 npm ERR! file sh npm ERR! path sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn sh npm ERR! site-web@1.0.0 build-prod: `webpack --config /var/app/current/webpack.prod.config.js` npm ERR! spawn sh ENOENT npm ERR! npm ERR! Failed at the site-web@1.0.0 build-prod script 'webpack --config /var/app/current/webpack.prod.config.js'. npm ERR! This is most likely a problem with the site-web package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! webpack --config /var/app/current/webpack.prod.config.js npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs site-web npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm ERR! npm owner ls site-web npm ERR! There is likely additional logging output above. npm ERR! Linux 4.4.14-24.50.amzn1.x86_64 npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/node" "/bin/npm" "run" "build-prod" npm ERR! node v4.4.6 npm ERR! npm v2.15.5 npm ERR! code ELIFECYCLE 

container configuration file:

 container_commands: 01_node_symlink: command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node" 02_npm_symlink: command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm" 03_npm_install_global_packages: command: "npm install webpack webpack-cli -g" 04_webpack_symlink: command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/webpack /bin/webpack" #05_webpack_run_build_prod: #command: "webpack --config /var/app/current/webpack.prod.config.js --progress --colors" 06_npm_run_build_prod: command: "npm run build-prod" 

Scripts in package.json

 "scripts": { "build": "webpack --config webpack.local.config.js --progress --colors", "build-local": "webpack --config webpack.prod.config.js --progress --colors", "build-prod": "webpack --config /var/app/current/webpack.prod.config.js", "server": "node app.js", "dev-server": "node dev-app.js" } 

And when I uncomment 05, which runs the webpack command directly, it ends with the Error: "/var/app/current/site-web/static/assets/app/index.js" is not in the SourceMap. error Error: "/var/app/current/site-web/static/assets/app/index.js" is not in the SourceMap.

The script construct works successfully locally, but is blocked at all stages of production. Unable to figure out how to run the webpack command to create JS in the AWS beanstalk environment. Isn't that the perfect way to create a js file?

node: 4.4.6 npm: 2,15,5 webpack: last

+7
javascript webpack amazon-web-services elastic-beanstalk
source share
3 answers

I'm still new to creating an elastic beanstalk and a similar question in itself, but I noticed that your tasks are for symlinking node, npm, etc. presented in the form of container_commands .

According to official docs : "They start after the application and the web server are configured, and the application version file was extracted, but before the application version is deployed."

Perhaps try using commands: instead of container_commands: See the link I shared.

Maybe the fact that these commands do not start until the application and the web server are already configured, why they may not work for you?

Again, I'm still new to the elastic beanstalk, but maybe this can help.

+2
source share

I had problems with global npm installations (in my case, response scripts). As a workaround, I decided to install the dependent package as indicated in package.json and then symbolically attached to it (located in /tmp/deployment/application/node_modules/.bin on EC2) in the .ebextensions configuration .ebextensions :

  03_react_scripts_symlink: command: "ln -sf /tmp/deployment/application/node_modules/.bin/react-scripts /bin/react-scripts" 04_npm_run_build_prod: command: "sudo npm run build" 
0
source share

Finally, I was able to run the build script in the staging directory. This is not a permanent solution, but it works.

 05_webpack_run_build_prod: command: "cd /tmp/deployment/application && sudo webpack --config webpack.prod.config.js --progress --colors" 
-one
source share

All Articles