sindresorhus / ow

Function argument validation for humans
https://sindresorhus.com/ow/
MIT License
3.8k stars 105 forks source link

SyntaxError: invalid regexp group #172

Closed NavidMitchell closed 3 years ago

NavidMitchell commented 4 years ago

This may be completely unrelated to your project. I have tried to include your library into my project which is a vue.js app built with vue cli and using typscript. After importing your library when I launch my project I just get the following error in my console.

SyntaxError: invalid regexp group chunk-vendors.js:1:7

If I remove the usage of the ow library it goes away. Any help would be appreciated. I have never encountered this sort of error before.

Thank you, Navid

neptunelabs commented 4 years ago

I'm experiencing the same error after updating ow to version 0.16.0 in my project.

0.16.0 and 0.17.0 work fine in Google Chrome, but not in Firefox (error:"SyntaxError: invalid regexp group") nor in Edge (error: "Expected identifier, string or number").

0.15.1 is the last version running without syntax errors in my project with all browsers.

Regretfully I can't tell exactly where the error occurs in ow, as I use a ow in a webpack'ed script in my project.

Target of my project is es2017.

Cheers, Hanno

sindresorhus commented 4 years ago

The only place we use a regex not supported by Firefox is: https://github.com/sindresorhus/ow/blob/b2285d0d4fe59def762bd989cab067d8d9b66eab/source/utils/infer-label.ts#L7

But that file is excluded for browser use: https://github.com/sindresorhus/ow/blob/b2285d0d4fe59def762bd989cab067d8d9b66eab/package.json#L80-L82

Which makes it sound like Vue CLI doesn't respect the browser field. If that's the case, you should open an issue on Vue CLI.

neptunelabs commented 4 years ago

Thanks for the reply! I don't use Vue CLI, but webpack CLI (version 3.3.11). So it looks like webpack doesn't support the conditionals in the "browser" section of your package.json either.

jorcalle11 commented 4 years ago

Hey there!

I got the same error when tried to deploy a serverless function to GCP that uses this module. This is how the error looks like:

!  functions[contact(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: SyntaxError: Invalid regular expression: /^.*?\((?<label>.*?)[,)]/: Invalid group
    at Object.<anonymous> (/srv/node_modules/ow/dist/source/index.js:1:26679)
    at r (/srv/node_modules/ow/dist/source/index.js:1:186)
    at Object.module.exports.r (/srv/node_modules/ow/dist/source/index.js:1:11962)
    at r (/srv/node_modules/ow/dist/source/index.js:1:186)
    at module.exports.Object.defineProperty.value (/srv/node_modules/ow/dist/source/index.js:1:985)
    at Object.<anonymous> (/srv/node_modules/ow/dist/source/index.js:1:994)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)

Platform: node 8 ow version: 0.17.0

jorcalle11 commented 4 years ago

Never mind, I just saw in the releases section that versions higher to v0.15.1 have breaking changes with the node version. It requires Node.js 10 or higher.

I downgraded the version on my project to v015.1 and I could deploy my function without a problem. Thanks for doing this package.

sindresorhus commented 4 years ago

So it looks like webpack doesn't support the conditionals in the "browser" section of your package.json either.

That would be surprising as Webpack popularized the browser field. I would open an issue on Webpack about this.

nullfame commented 4 years ago

@neptunelabs, did you ever file this elsewhere?

Also experiencing this issue with Vue CLI 4.3.1 (2020-04-07). Would gladly contribute a fix. The pragmatic side of me says changing this one line in this one package is the easiest. Replacing ow in my repos is next easiest. Getting Babel or Vue to change is the least likely to resolve in the near-term.

neptunelabs commented 4 years ago

@nullfame: I didn't file this anywhere else except here. As you can see here @sindresorhus suspects the problem in Webpack and Vue not supporting conditionals in the "browser" section of the package.json properly. I didn't dig deeper into this yet and stick with version 0.15.1 for now.