在严格模式之外尚不支持块作用域声明
Block-scoped declarations not yet supported outside strict mode
我正在 运行宁 Laravel 5.4 在我的 Homestead vagrant box 上。我已经使用 npm install
命令安装了所有 npm 依赖项。那没有产生任何错误。
在我的 webpack.min.js 文件中我有:
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');
当我想 运行 npm run production
我收到以下错误:
> @ 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
这可能是什么问题?
您的节点未更新。
删除您的节点版本,download并安装最新版本。
在项目根目录中 运行:
npm rebuild
然后重试:
npm run production
PS.: 如果你不想删除你的节点版本,用这个下载新的和 运行。
我在 Ubuntu 上遇到了旧版 nodejs 包引起的相同问题。我刚刚更新到 7.5,它正在运行。
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
升级节点包是这里的解决方案。添加替代步骤来升级节点包,因为无需自己下载、安装和管理节点版本。您可以使用名为 n
的模块来升级 Mac/Ubuntu
中的节点包
sudo npm install -g n
sudo n stable
这将安装最新的稳定节点包。你可以运行
node --version
如果您仍然看到旧版本,则可能是安装新包的目录问题。我必须创建一个符号链接才能使其工作-
sudo ln -s /usr/local/n/versions/node/9.0.0/bin/node /usr/local/bin/node
我在 NodeJS 中的一个测试脚本遇到了同样的问题,我通过使用 ECMAScript 5 的严格模式解决了我的错误。
"use strict";
在我的脚本顶部添加了上面一行,效果很好。
严格模式对正常 JavaScript 语义进行了一些更改:
通过将一些 JavaScript 静默错误更改为抛出错误来消除它们。
修复了导致 JavaScript 引擎难以执行优化的错误:严格模式代码有时可以 运行 比非严格模式的相同代码更快。
禁止某些可能在未来版本的 ECMAScript 中定义的语法。
这是因为您的机器上没有最新版本的 NodeJS。
我在 Ubuntu 所以如果你在任何类型的 Linux 发行版试试这个。
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs
我也遇到了同样的问题,我已经尝试 运行 这些命令,现在可以了。 但在此之前先卸载nodejs
sudo apt-get update
apt-cache policy nodejs
sudo apt install nodejs
希望你的问题得到解决
$ npm run dev
> @ dev /var/www/laratest2
> npm run development
> @ development /var/www/laratest2
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
/var/www/laratest2/node_modules/laravel-mix/setup/webpack.config.js:6
let mix = require('../src/index');
^^^
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:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at requireConfig (/var/www/laratest2/node_modules/webpack/bin/convert-argv.js:97:18)
at /var/www/laratest2/node_modules/webpack/bin/convert-argv.js:104:17
at Array.forEach (native)
npm ERR! Linux 4.15.0-45-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "development"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! @ development: `cross-env NODE_ENV=development 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 @ development script 'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, 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! cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs
npm ERR! Or if that isn't available, 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! /var/www/laratest2/npm-debug.log
npm ERR! Linux 4.15.0-45-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev script 'npm run development'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, 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! npm run development
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs
npm ERR! Or if that isn't available, 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! /var/www/laratest2/npm-debug.log
当我 运行 宁 npm run dev
我得到了上述错误,这是因为我有旧版本的 nodejs。
使用以下命令更新nodejs包。
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs
您可以使用以下方式检查版本:
node -v
npm -v
现在运行以下命令:
npm rebuild
然后尝试 运行ning npm run dev
,它对我有用。
输出
DONE Compiled successfully in 9626ms 3:14:07 PM
Asset Size Chunks Chunk Names
/css/app.css 226 kB 0 [emitted] mix
我正在 运行宁 Laravel 5.4 在我的 Homestead vagrant box 上。我已经使用 npm install
命令安装了所有 npm 依赖项。那没有产生任何错误。
在我的 webpack.min.js 文件中我有:
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');
当我想 运行 npm run production
我收到以下错误:
> @ 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
这可能是什么问题?
您的节点未更新。
删除您的节点版本,download并安装最新版本。
在项目根目录中 运行:
npm rebuild
然后重试:
npm run production
PS.: 如果你不想删除你的节点版本,用这个下载新的和 运行。
我在 Ubuntu 上遇到了旧版 nodejs 包引起的相同问题。我刚刚更新到 7.5,它正在运行。
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
升级节点包是这里的解决方案。添加替代步骤来升级节点包,因为无需自己下载、安装和管理节点版本。您可以使用名为 n
的模块来升级 Mac/Ubuntu
sudo npm install -g n
sudo n stable
这将安装最新的稳定节点包。你可以运行
node --version
如果您仍然看到旧版本,则可能是安装新包的目录问题。我必须创建一个符号链接才能使其工作-
sudo ln -s /usr/local/n/versions/node/9.0.0/bin/node /usr/local/bin/node
我在 NodeJS 中的一个测试脚本遇到了同样的问题,我通过使用 ECMAScript 5 的严格模式解决了我的错误。
"use strict";
在我的脚本顶部添加了上面一行,效果很好。
严格模式对正常 JavaScript 语义进行了一些更改:
通过将一些 JavaScript 静默错误更改为抛出错误来消除它们。
修复了导致 JavaScript 引擎难以执行优化的错误:严格模式代码有时可以 运行 比非严格模式的相同代码更快。
禁止某些可能在未来版本的 ECMAScript 中定义的语法。
这是因为您的机器上没有最新版本的 NodeJS。 我在 Ubuntu 所以如果你在任何类型的 Linux 发行版试试这个。
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs
我也遇到了同样的问题,我已经尝试 运行 这些命令,现在可以了。 但在此之前先卸载nodejs
sudo apt-get update
apt-cache policy nodejs
sudo apt install nodejs
希望你的问题得到解决
$ npm run dev
> @ dev /var/www/laratest2
> npm run development
> @ development /var/www/laratest2
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
/var/www/laratest2/node_modules/laravel-mix/setup/webpack.config.js:6
let mix = require('../src/index');
^^^
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:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at requireConfig (/var/www/laratest2/node_modules/webpack/bin/convert-argv.js:97:18)
at /var/www/laratest2/node_modules/webpack/bin/convert-argv.js:104:17
at Array.forEach (native)
npm ERR! Linux 4.15.0-45-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "development"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! @ development: `cross-env NODE_ENV=development 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 @ development script 'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, 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! cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs
npm ERR! Or if that isn't available, 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! /var/www/laratest2/npm-debug.log
npm ERR! Linux 4.15.0-45-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev script 'npm run development'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, 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! npm run development
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs
npm ERR! Or if that isn't available, 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! /var/www/laratest2/npm-debug.log
当我 运行 宁 npm run dev
我得到了上述错误,这是因为我有旧版本的 nodejs。
使用以下命令更新nodejs包。
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs
您可以使用以下方式检查版本:
node -v
npm -v
现在运行以下命令:
npm rebuild
然后尝试 运行ning npm run dev
,它对我有用。
输出
DONE Compiled successfully in 9626ms 3:14:07 PM
Asset Size Chunks Chunk Names
/css/app.css 226 kB 0 [emitted] mix