Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Invalid regular expression #9456

Closed
inherithandle opened this issue Feb 8, 2019 · 9 comments · Fixed by #9595
Closed

SyntaxError: Invalid regular expression #9456

inherithandle opened this issue Feb 8, 2019 · 9 comments · Fixed by #9595

Comments

@inherithandle
Copy link

Version

2.6.3

Reproduction link

https://github.com/inherithandle/vue-webpack-simple-project

Steps to reproduce

  1. git clone https://github.com/inherithandle/vue-webpack-simple-project
  2. run "npm install"
  3. run "npm run build"
  4. open ./dist/index.html

What is expected?

I expected index.html to be rendered successfully.

What is actually happening?

I get the error: "SyntaxError: invalid range in character class"


I think it is similar to the issue #2291.

@aizquier
Copy link

I have the same problem. The bug seems to have been introduced since the version 2.6.0.

@inherithandle inherithandle reopened this Feb 28, 2019
@Justineo
Copy link
Member

It seems to be caused by Terser.

You can workaround this as follows for now:

const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  entry: './src/js/vue-first.js',
  output: {
    filename: 'todo.js',
    path: path.resolve(__dirname, 'dist')
  },
  optimization: {
    minimizer: [
      new TerserPlugin({
        cache: true,
        parallel: true,
        sourceMap: true,
        terserOptions: {
          output: {
            ascii_only: true // <- Add this to keep the regex valid
          }
        }
      }),
    ],
  }
};

@posva
Copy link
Member

posva commented Feb 28, 2019

I'm taking a look at this

@posva
Copy link
Member

posva commented Feb 28, 2019

I couldn't spend more time on this for now but it's weird since using raw terser with the regex at https://github.com/vuejs/vue/blob/dev/src/core/util/lang.js#L8, and more specifically new RegExp('[^\uF900-\uFDCF]') yields a valid result (the same we have in project with the CLI). It's as if the problem was with webpack. We cannot really expand the regex as it would be too much either

@yyx990803
Copy link
Member

/cc @sodatea not sure if this is affecting the CLI which also uses Terser. Maybe it has to do with a specific version of Terser?

@sodatea
Copy link
Member

sodatea commented Feb 28, 2019

It works with http, but not file:///

@sodatea
Copy link
Member

sodatea commented Feb 28, 2019

Or with charset="utf8" attribute on the script tag.
So the issue is browser's auto charset detection.
Not sure how to fix it.

@sodatea
Copy link
Member

sodatea commented Feb 28, 2019

So, as I tested out on https://xem.github.io/terser-online/, unicode sequences in strings (e.g. '\uF900-\uFDCF') are compressed into single characters, while those in regexps aren't (e.g. /\uF900-\uFDCF/). It'll be an easy fix.

@dandelion1000
Copy link

this may be node version, just me try run build or run dev in localhost, is ok, however,when i build it in server, just throw npm audit fix, Invalid regular expression ... so upgrade node --version ,is build success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants