Webpack-encore: Error: Invalid identity escape in regular expression

Created on 4 May 2020  路  4Comments  路  Source: symfony/webpack-encore

I have migrated react app to Symfony and now getting SyntaxError: invalid identity escape in regular expression. App worked before compiled by yarn but now with encore its stucked on this error. I try adding babel plugins

.configureBabel(function(babelConfig) {
        babelConfig.plugins.push('transform-class-properties');
        babelConfig.plugins.push('@babel/plugin-proposal-class-properties');
        babelConfig.plugins.push(["@babel/plugin-proposal-unicode-property-regex", { "useUnicodeFlag": false }]);
    })

but it wasn't help. I am trying it for week now. Can someone help me?

Most helpful comment

Hi @pajasry,

Since the error is coming from vendors~app.js it may be caused by a RegExp used in a vendor (those are not transpiled by Babel by default).

After looking at the content of your package.json could you try this?

Encore.configureBabel(function(babelConfig) {
    babelConfig.plugins.push('transform-class-properties');
    babelConfig.plugins.push('@babel/plugin-proposal-class-properties');
    babelConfig.plugins.push(["@babel/plugin-proposal-unicode-property-regex", { "useUnicodeFlag": false }]);
+ }, {
+    includeNodeModules: ['camelcase']
})

I suspect things like that line from camelcase are not well understood by Firefox :)

All 4 comments

Hi,

Can you post the whole stack trace (if available) or/and provide a reproduction repo?
Did you enable react preset (doc)?

The error is thrown by Firefox console and points on first line of vendor-app.js I simplified project to minimum and it's still here. You can look at it here. I find out, that when I compile only react app by yarn, it works. But compiling it with Symfony docs doesn't work

Hi @pajasry,

Since the error is coming from vendors~app.js it may be caused by a RegExp used in a vendor (those are not transpiled by Babel by default).

After looking at the content of your package.json could you try this?

Encore.configureBabel(function(babelConfig) {
    babelConfig.plugins.push('transform-class-properties');
    babelConfig.plugins.push('@babel/plugin-proposal-class-properties');
    babelConfig.plugins.push(["@babel/plugin-proposal-unicode-property-regex", { "useUnicodeFlag": false }]);
+ }, {
+    includeNodeModules: ['camelcase']
})

I suspect things like that line from camelcase are not well understood by Firefox :)

Thank you very much, I spend more than week on this issue. You are my savior. It was caused by bad support of new Regex in firefox rigth?

Was this page helpful?
0 / 5 - 0 ratings