Skip to content

Register does not transpile node_module dependencies  #769

Open
@albertogasparin

Description

@albertogasparin

I have a 3rd party dependency that internally relies on https://github.com/google/zx . Now zx does not publish with cjs, only ESM, and when I try to run my-script.ts that includes the dependency via:

 node --loader @swc-node/register/esm my-script.ts

I get an error:

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/zx/build/index.js from node_modules/3rd-party/dist/cjs/whatever.js not supported.
Instead change the require of index.js in node_modules/3rd-party/dist/cjs/whatever.js to a dynamic import() which is available in all CommonJS modules.

Obviously, cannot change the 3rd party dependency import statements. Also this was marked as "resolved" in #634 but seems like it works only on 1st level imports?

Other tools handle this properly (eg node -r esbuild-register) but I'd love to stick with SWC 🙏

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