Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Automatically transform only ESM packages under node_modules #139

@fregante

Description

@fregante

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions