The project that has been running very well suddenly reported an error in build. The error message is as follows:
ERROR in static/js/vendor.f1c68aa2d5e85847d30e.js from UglifyJs
Unexpected token name «i», expected punc «;» [./node_modules/element-ui/src/utils/merge.js:2,0][static/js/vendor.f1c68aa2d5e85847d30e.js:17064,11]
Build failed with errors.
In uglifyjs’ GitHub issues # 78, we found such a solution: because uglifyjs only supports Es5, and element UI may introduce a part of the writing of ES6, so webpack packaging fails. The final solution given in issue is to replace uglify JS with uglify es of beta version (beta version introduces support for es2015 +). You need to execute the command NPMI - D in the front-end working directory uglifyjs-webpack-plugin@beta
。
However, after trying, we found that the problem of build error is still unsolved. After searching for the problem, we decided to use bable to parse the element UI. To complete this operation, we only need to modify the build error in the front-end folder/ webpack.base.conf The. JS file can be modified as follows:
before modification
module: {
rules: [
...
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test')]
},
After modification
module: {
rules: [
...
{
test: /\.js$/,
loader: 'babel-loader',//Note that elementUI's source code needs to be parsed using ES6
include: [resolve('src'), resolve('test'),resolve('/node_modules/element-ui/src'),resolve('/node_modules/element-ui/packages')]
},
...
It is equivalent to adding element UI to the package that needs to be parsed by Babel.
After that, execute NPM run build
again, and the build is successful.
Read More:
- Solution to some map files in JS folder after Vue packaging (remove the map. JS file)
- vue.config.js build Package UglifyJsPlugin to clear console and print console.log Error: `warnings` is not a supported option
- [Solved] webpack Package Error: ERROR in multi ./src/main.js ./dist/bundle.js Module not found: Error: Can‘t resolv
- [Solution] VUE.js Load a local image with parameters in the script
- [Solved] Failed to load plugin ‘vue‘ declared in ‘.eslintrc.js‘: createRequire is not a function
- [Solved] vue.esm.js?efeb:591 [Vue warn]: Error in event handler for “click“: “TypeError: Cannot read property
- [Solved] Nuxt Import qrcodejs2.js / QRCode.js Error: document is not defined
- [Solved] Turf.js error: uncaught (in promise) error: the solution of invalid unit
- [Solved] NPM node ERROR in main..js from Terser ChildProcessWorker.initialize Excaption
- The solution to the problem that the custom styles of UI components such as element-ui in the vue project do not take effect
- Module not found: Error: Can‘t resolve ‘core-js/modules/es.promise.js‘ in
- Vue Package Image Error: Syntax Error: Error: ‘**\node_modules\pngquant-bin\vendor\pngquant.exe‘
- [Solved] Layui 404 Error: Static resources cannot load layui.js and layui. css
- Vue Import three.JS error: Unexpected token [How to Solve]
- The addition, deletion and modification of DOM in JS Foundation
- Vue JS import font.css error [How to Solve]
- The solution to the failure of HTML introducing external JS
- [Solved] This dependency was not found: * core-js/modules/es.error.cause.js in ./node_modules/_@babel_runtim
- JS getting ${pageContext.request.contextPath} Get the root path of the project
- [Solved] ERROR Error loading vue.config.js: ERROR Error: Command failed: git describe