Ich laufe Laravel 5.4 auf meiner Viehkiste von Homestead. Ich habe alle npm-Abhängigkeiten mit dem Befehl npm install
installiert. Das hat keine Fehler erzeugt.
In meiner webpack.min.js -Datei habe ich:
const { mix } = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js([
'resources/assets/plugins/jquery-1.11.3.min.js',
'resources/assets/plugins/bootstrap/js/bootstrap.min.js',
'resources/assets/js/main.js'
], 'public/js'
);
mix.combine([
'resources/assets/plugins/bootstrap/css/bootstrap.min.css',
'resources/assets/plugins/font-awesome/css/font-awesome.css',
'resources/assets/css/styles.css'
], 'public/css/all.css');
Wenn ich npm run production
ausführen möchte, erhalte ich folgende Fehler:
> @ production /home/vagrant/projects/nielsvroman
> node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
/home/vagrant/projects/nielsvroman/node_modules/laravel-mix/setup/webpack.config.js:120
let extractPlugin = new plugins.ExtractTextPlugin(
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:404:25)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at requireConfig (/home/vagrant/projects/nielsvroman/node_modules/webpack/bin/convert-argv.js:96:18)
at /home/vagrant/projects/nielsvroman/node_modules/webpack/bin/convert-argv.js:109:17
at Array.forEach (native)
npm ERR! Linux 3.19.0-25-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "production"
npm ERR! node v5.0.0
npm ERR! npm v3.3.6
npm ERR! code ELIFECYCLE
npm ERR! @ production: `node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ production script 'node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'.
npm ERR! This is most likely a problem with the package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! You can get their info via:
npm ERR! npm owner ls
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/vagrant/projects/nielsvroman/npm-debug.log
Was könnte das Problem sein?
Ich hatte das gleiche Problem, das durch die alte Version des nodejs-Pakets auf Ubuntu verursacht wurde. Ich habe gerade auf 7.5 aktualisiert und es funktioniert.
curl -sL https://deb.nodesource.com/setup_7.x | Sudo -E bash -
Sudo apt-get install -y nodejs
Das Upgrade des Knotenpakets ist hier die Lösung. Hinzufügen alternativer Schritte zum Aktualisieren des Knotenpakets, da keine Knotenversionen selbst heruntergeladen, installiert und verwaltet werden müssen. Sie können ein Modul namens n
verwenden, um das Knotenpaket in Mac/Ubuntu zu aktualisieren
Sudo npm install -g n
Sudo n stable
Dadurch wird das neueste stabile Knotenpaket installiert. Du kannst rennen
node --version
Wenn Sie immer noch die alte Version sehen, kann es sich um Verzeichnisprobleme handeln, bei denen ein neues Paket installiert wird. Ich musste einen Symlink erstellen, damit es funktioniert.
Sudo ln -s /usr/local/n/versions/node/9.0.0/bin/node /usr/local/bin/node
Ihr Knoten wurde nicht aktualisiert.
entfernen Sie Ihre Knotenversion, download und installieren Sie die neueste Version.
im Projektstammlauf:
npm rebuild
Und versuche es noch mal:
npm run production
PS .: Wenn Sie Ihre Knotenversion nicht entfernen möchten, laden Sie die neue Version herunter und führen Sie diese aus.
Ich hatte das gleiche Problem mit einem meiner Testskripts in NodeJS und ich habe meinen Fehler durch den strikten Modus von ECMAScript 5 behoben.
"use strict";
Oben angezeigte Zeile oben in meinem Skript hinzugefügt, und es funktioniert gut.
Der strikte Modus nimmt einige Änderungen an der normalen JavaScript-Semantik vor:
Beseitigt einige stille JavaScript-Fehler, indem sie geändert werden, um Fehler auszulösen.
Behebt Fehler, die es für JavaScript-Engines schwierig machen, Optimierungen durchzuführen: Strenger Modus-Code kann manchmal schneller ausgeführt werden als identischer Code, der nicht strikt ist.
Verbietet eine Syntax, die in zukünftigen Versionen von ECMAScript wahrscheinlich definiert wird.
Ich hatte auch das gleiche Problem und habe versucht, diesen Befehl auszuführen, und jetzt funktioniert es. Deinstallieren Sie vorher die nodejs
Sudo apt-get update
apt-cache policy nodejs
Sudo apt install nodejs
Ich hoffe dein Problem ist gelöst.
Dies liegt daran, dass Sie nicht die neueste Version von NodeJS auf Ihrem Computer installiert haben. Ich bin auf Ubuntu.
curl -sL https://deb.nodesource.com/setup_11.x | Sudo -E bash -
Sudo apt-get install -y nodejs