Skip to content

Imports mapping wildcard support #2044

Open
@CMCDragonkai

Description

@CMCDragonkai

Search Terms

  • imports mapping
  • wildcard

Expected Behavior

The imports mapping key in package.json is a new way of specifying internal imports.

I've noticed that ts-node does not appear to understand unless all mappings are specified literally.

For example if this is done:

  "imports": {
    "#*.js": "./dist/*.js"
  },

This allows node to import #index.js without any problems.

Actual Behavior

However if I use ts-node, it complains that

/home/cmcdragonkai/Projects/js-logger/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:374
  throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
        ^
CustomError: ERR_PACKAGE_IMPORT_NOT_DEFINED #index.js

In order to fix this, it is necessary to to define the mapping explicitly:

  "imports": {
    "#index.js": "./dist/index.js",
    "#*.js": "./dist/*.js"
  },

Steps to reproduce the problem

Create a new package with "imports" key as above.

Create a file that imports:

import x from '#index.js';

Name it .js, run it with node.

Then name it .ts and run it with ts-node.

Minimal reproduction

  "ts-node": {
    "esm": true
  }

Specifications

  • ts-node version: v10.9.1
  • node version: node v18.15.0
  • TypeScript version: compiler v5.1.6

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