[Solution] ERROR in xxx.js from UglifyJs

created at 07-07-2021 views: 3

problem

When we run the packaging script npm run build or package ios weexpack build ios, we may encounter the following error

ERROR in index.js from UglifyJs
Unexpected token:punc (() [index.js:198,8])...

This is because webpack did not successfully convert the ES6 syntax when packaging the vue file.

Solution

The solution is very simple, just add babel-preset-es2015 plugin

1. Install dependent packages

$ npm install --save-div babel-preset-es2015

ps: babel-loader and babel-core should be installed by default, if not installed, please reinstall

2. Modify [webpack.config.js] configuration file

Find the rules of /\.js$/ and modify

      {
        test: /\.js$/,
        use: [{
          loader: 'babel-loader',
          options: {
             presets: ['es2015']
          }
        }]
      }

3. Add [.babelrc] file in the root directory

content

{
  "presets": ["es2015"]
}

Retry

Re-run the packaging script to check the effect, the instruction depends on the situation

$ npm run build
Please log in to leave a comment.