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

Automatically transform only ESM packages under node_modules #139

Open
fregante opened this issue Jan 18, 2023 · 0 comments
Open

Automatically transform only ESM packages under node_modules #139

fregante opened this issue Jan 18, 2023 · 0 comments

Comments

@fregante
Copy link
Contributor

I'm using Jest without the experimental ESM support, this means SWC must run on ES Module dependencies. Ideally I'd just let it transform the entire node_modules folder but that slows down the tests considerably, so I have to use transformIgnorePatterns with node_modules plus an increasingly-long list of manually-excluded ES Modules. I'm now at 24+.

https://github.com/pixiebrix/pixiebrix-extension/blob/fee28636efcad73745a7cc8d4c52649dd31db422/jest.config.json#L7-L22

Is there a way to configure SWC via .swcrc to automatically skip CJS modules? That would allow me to avoid transformIgnorePatterns altogether.

I'll paste the actual error for googlability:

./node_modules/linkify-urls/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){
   import createHtmlElement from 'create-html-element';                                                                                      
   ^^^^^^
   SyntaxError: Cannot use import statement outside a module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant