7

Ich habe einen Knoten js App bei elasticbeanstalk bereitgestellt. Installierter und symbolisierter Knoten, npm und webpack. Aber wenn npm run build-prod ausgeführt wird, ruft das Skript selbst webpack --config /var/app/current/webpack.prod.config.js auf. Den folgenden Fehler mit dem Exit-Status -2 erhalten. Das gleiche passiert, wenn ich den Befehl webpack auch direkt ausführe. Ich suche nach Lösungen.AWS Elastic Beanstalk - Erstellen von Bundle JS mit npm und webpack

[2016-07-26T06:57:36.301Z] INFO [9731] - [Application update [email protected]/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_site_web/Command 06_npm_run_build_prod] : Activity execution failed, because: 
    > [email protected] 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! [email protected] build-prod: `webpack --config /var/app/current/webpack.prod.config.js` 
    npm ERR! spawn sh ENOENT 
    npm ERR! 
    npm ERR! Failed at the [email protected] 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-Konfigurationsdatei:

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" 
    } 

Und wenn ich Kommentar- 05, der die webpack Befehl ausgeführt wird direkt endet mit Fehler Error: "/var/app/current/site-web/static/assets/app/index.js" is not in the SourceMap.

Das Build-Skript ist erfolgreich auf lokaler, aber auf allen Wegen bei der Produktion blockiert. Konnte nicht herausfinden, wie man den Befehl webpack ausführt, um die JS in der AWS-Beanstalk-Umgebung zu erstellen. Ist das nicht der ideale Weg, die JS-Datei zu erstellen?

Knoten: 4.4.6 npm: 2.15.5 webpack: neueste

+1

Mai werden/var/app/Strom/webpack Datei .prod.config.js fehlt? –

+0

Es ist da. Ich verwende 'eb deploy', um den Code und ssh bereitzustellen, um zu überprüfen, dass die Datei dort und das Build-Skript manuell ausgeführt werden kann. – Babu

Antwort

2

Ich bin noch neu in elastischen Bohnenstengel und mit ähnlichen Problemen selbst, aber ich bemerkte, Ihre Aufgaben für SymLink Knoten, npm, etc, sind in Form von container_commands.

According to the official docs, "Sie werden ausgeführt, nachdem die Anwendung und der Webserver eingerichtet wurden und die Anwendungsversionsdatei extrahiert wurde, aber bevor die Anwendungsversion bereitgestellt wird."

Vielleicht versuchen Sie mit commands: anstelle von container_commands:. Siehe Link, den ich geteilt habe.

Vielleicht ist die Tatsache, dass diese Befehle erst ausgeführt werden, nachdem die Anwendung und der Web-Server bereits eingerichtet wurden, der Grund dafür, dass es möglicherweise nicht für Sie funktioniert?

Wieder bin ich noch neu zu elastischen Bohnenstangen aber vielleicht kann das helfen.

+0

In Befehlen versucht, aber kein Glück. – Babu

+0

BTW, was bedeutet es genau "ist im Einsatz"? Ich denke, die Containerbefehle werden ausgeführt, sobald die App-Versionsdateien im Bereitstellungsverzeichnis abgelegt werden. So funktioniert es mit meiner Python-Django-Umgebung, wenn ich den migrate-Befehl in container_commands ausführe. – Babu

+0

Sorry, nicht sicher, was genau mit "ist im Einsatz" gemeint ist – Danny

-1

Schließlich konnte ich das Build-Skript im Staging-Verzeichnis ausführen. Es ist keine dauerhafte Lösung, aber es funktioniert.

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

Ich hatte Probleme mit globalen Npm-Installationen (in meinem Fall reagieren-Skripte). Was ich als Behelfslösung tat, war das abhängige Paket zu installieren, wie in package.json erklärt und dann Symlink, um es (bei /tmp/deployment/application/node_modules/.bin auf EC2 befindet) in der .ebextensions Konfigurationsdatei:

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"