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

Not working with esbuild/vite #182

Open
DiscreteTom opened this issue Mar 31, 2023 · 1 comment
Open

Not working with esbuild/vite #182

DiscreteTom opened this issue Mar 31, 2023 · 1 comment

Comments

@DiscreteTom
Copy link

Thanks for this cool lib!

I'm trying to use this lib in a frontend project using vite, when I build my project with esbuild I got the following error:

Illegal reassignment to import 'commonjsRequire'
file: C:/Users/xxx/node_modules/markdown-toc/lib/utils.js:10:0
 8: var utils = require('lazy-cache')(require);
 9: var fn = require;
10: require = utils;
    ^
11: 
12: /**

Looks like require is a reserved word and can't be changed, so how to solve this?

@doowb
Copy link
Collaborator

doowb commented Apr 4, 2023

In JavaScript, require is not reserved, however many bundling tools do things to make it seem like it is.

For webpack, the unlazy-loader transforms the pattern used in this utils.js file, so that require is not reassigned.

I'm not as familiar with vite (is it using esbuild?), but there might be a way to configure transformation plugins in a similar fashion. If there isn't a direct way to use a webpack plugin with vite, the unlazy-loader function could be wrapped in a way to adapter to vite.

I hope this helps, and if you try something that works (or almost works), please let us know.

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

No branches or pull requests

2 participants