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

'require' in string will be unexpectedly parsed. eg. console.log("var foo = require('foo')") #27

Open
MecDog opened this issue Feb 23, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@MecDog
Copy link

MecDog commented Feb 23, 2022

Versions

  • originjs: 1.0.2
  • node: 14.18.1

Reproduction

source code:

 console.error("You need to import react !\nExample: react=require('react')");

'vite-plugin-commonjs' output:

import * as __require_for_vite_iuMxJX from "react"
console.error("You need to import react !\nExample: react=__require_for_vite_iuMxJX");
@flyfishzy
Copy link
Member

It's a little difficult to identify require in a string by RegExp. I've considered using a AST, but this will slow down transform.

@nwoltman
Copy link

I have the same problem. Perhaps there could be an option to use an AST for those who need it? I'd rather have this plugin be slower than not work at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants