V
V
Vlad2021-02-17 00:59:45
gulp.js
Vlad, 2021-02-17 00:59:45

Why doesn't the code from the `highlight.js` npm package want to be aggregated in production? How to fix it?

In main.js I import, among other imports , highlight.js :

import hljs from 'highlight.js';
hljs.highlightAll();


I run all the JS code in Galp through Webpack:
...
.pipe(webpackStream({
            mode: `${(devMode === true) ? 'development' : 'production'}`, // translate our mode for webpack
            output: {
                filename: `${path.build.jsOutput}`,  // specify just one output file
            },
            module: {
                rules: [
                    {
                        test: /\.(js)$/,    // get all the js-files
                        exclude: /(node_modules)/, // exclude development modules folder
                        loader: 'babel-loader', // convert ES6 into a backwards compatible version of JS
                        query: {
                            presets: ['@babel/env'] // use babel preset
                        }
                    },
                ]
            },
            optimization: {
                minimizer: [
                  new UglifyJsPlugin({      // minify JS
                    uglifyOptions: {
                      output: {
                        comments: false,    // disable even special comments
                      },
                    },
                  }),
                ],
            }
        })).on('error', function handleError() {
            this.emit('end')
        })
...


When I put it on production, I see in the console:
ERROR in main.js from UglifyJs
Unexpected token: name «Response», expected: punc «;» [main.js:22946,6]


Empirically, I determine that this is `highlight.js`.

How to fix it? Do not chain with cdn :(

https://www.npmjs.com/package/highlight.js

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question