-
-
Notifications
You must be signed in to change notification settings - Fork 18
Doesn't handle package.json imports field #45
Copy link
Copy link
Open
Description
the chalk uses imports in the package.json. these start with a #. I'm not sure of the full semantics of how this "should" work. It might be as simple as switching this:
- if (/^\w+\:?/.test(ident)) return fallback(ident, context, fallback);
+ if (/^(\w+\:?|#)/.test(ident)) return fallback(ident, context, fallback);but that might be too naive to work in every case.
It seems to be because the check function calls fileURLToPath from url, which strips the # and following text, meaning that the check function ends up just checking if the parentURL exists.
I think the full solution to this would be to, if there's a # at the start of the import, call fallback and then process the result of fallback, as it might resolve to a typescript file. It might be enough to just ignore any # files and assume that the package exposing them is not using typescript?
Repro Steps
mkdir imports-report && cd imports-repronpm init -ynpm add chalk tsmecho "import chalk from 'chalk';" > index.mjsnode --loader tsm index.mjs
you'll see
file:///<folder>/imports-repro/node_modules/chalk/source/index.js#supports-color.mts:7
const { stdout: stdoutColor, stderr: stderrColor } = supportsColor;
^
TypeError: Cannot destructure property 'stdout' of 'supportsColor' as it is undefined.
at file:///<folder>/imports-repro/node_modules/chalk/source/index.js#supports-color.mts:7:17
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:527:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels