Fresh npm install of webpack.js is throwing Block-scope error

流过昼夜 提交于 2019-12-05 01:45:23
Manikandan Velayutham

Go to Tools > Options > Projects and Solutions > Web Package Management > External Web Tools DESELECT the option for $(VSINSTALLDIR)\Web\External.

Refer to Visual Studio Task Runner Error with ES6 and to Visual Studio Task Runner "SyntaxError: Use of const in strict mode."

Had this same issue today, for anyone else finding this, the resolution was to simply ensure node and npm were up to date. Updating those (recommend looking at nvm to achieve this) then re-installing the webpack and webpack-cli packages and all was sorted.

Try to add a loader for ES6 systax like babel and its presets. You can do that doing: npm install after adding this dependencies inside package.json (my dependencies is not updated, you can update them without problems):

"devDependencies": {
"babel-core": "^6.24.0",
"babel-loader": "^7.0.0",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.24.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-0": "^6.22.0",
}

Also, you must add this into your webpack.config.js > loaders (to set the new loader - babel-loader -):

loaders: [
        {
            test: /\.(js|jsx)$/,
            loader: 'babel-loader',
            query: {
                presets: [
                    'es2015',
                    'react',
                    'stage-0'
                ],
                plugins: [
                    'react-html-attrs',
                    'transform-decorators-legacy',
                    'transform-class-properties'
                ],
                compact: true
            }
        }
    ]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!