vite-plugins icon indicating copy to clipboard operation
vite-plugins copied to clipboard

CommonJS plugin fails when strings contain comment markers

Open mercurio opened this issue 3 years ago • 0 comments

Versions

  • node: 10.19.0

Reproduction

Attempt to import a minimized CommonJS module (I'm using zingchart-nodejs.min via @zingsoft/zingchart-svelte).

What is Expected?

It should be imported with no errors.

What is actually happening?

An error regarding an unterminated string is reported. The location given is for a comment marker // in the middle of a quoted string.

I took a look at the code (src/lib.ts). It looks as though you're stripping comments out without handling the case where the comment marker is inside a quoted string.

Perhaps the easiest way to fix this is to add an option to specify that the module you're importing is already minified and has no comments, and then don't call removeComments() if this option is enabled. Alternatively, you can just remove removeComments() completely, it doesn't matter if you convert a require into an import inside a comment.

mercurio avatar Apr 05 '22 20:04 mercurio