Skip to content

[@swc-node/register] passing flag --condition (-C) to node with esm-register import has no effect #890

Description

@mkvlrn

In order to resolve user conditions defined in package.json we're supposed to pass a flag to node indicating which condition is to be used.

In my package.json:

"imports": {
  "#*": {
    "dev": "./src/*",
    "default": "./dist/*"
  }
},
node -C dev --import @swc-node/register/esm-register src/main.ts

^ this does not pass the -C flag to node and any imports are searched in the default path, in ./dist.

I could not find anything regarding this flag in this repo, but I assume it is supposed to work the way tsx does:

node -C dev --import tsx src/main.ts

^ this passes the flag to node and the correct imports are used

edit: browsing the source I found this regarding conditions

conditionNames: ['node', 'import'],

and out of curiosity I've updated it locally to:

conditionNames: ['node', 'import', 'dev'],

and it worked as I thought it would be in the first attempt.

This is a local hack just to see if it works and I have no idea what could be done to allow it to work properly. Hoping someone competent can take a look at this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions