Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package.json "imports" field support #724

Open
MrFoxPro opened this issue Aug 17, 2023 · 0 comments
Open

package.json "imports" field support #724

MrFoxPro opened this issue Aug 17, 2023 · 0 comments

Comments

@MrFoxPro
Copy link

There is https://nodejs.org/api/packages.html#imports and resolvePackageJsonImports in tsconfig.json.
My configuration:

import eql from '#eql'

tsconfig.json:

"compilerOptions": {
  "strict": true,
  "baseUrl": ".",

  "target": "ESNext",
  "module": "NodeNext",
  "moduleResolution": "NodeNext",
  "resolvePackageJsonImports": true,

  "noEmit": true,
  "isolatedModules": true,

  "skipDefaultLibCheck": true,
  "skipLibCheck": true,
},
// ...

package.json:

"type": "module",
"imports": {
  "#eql": "./eql/index.mts"
},
// ...

Running node --loader=@swc-node/register/esm main.ts results in:

node:internal/process/esm_loader:46
      internalBinding('errors').triggerUncaughtException(
                                ^
RangeError [ERR_UNKNOWN_MODULE_FORMAT]: Unknown module format: undefined for URL file:///home/foxpro/craft/sferadel/dev/api/eql/index.mts
    at new NodeError (node:internal/errors:405:5)
    at Object.throwUnknownModuleFormat (node:internal/modules/esm/load:155:9)
    at Hooks.load (node:internal/modules/esm/hooks:417:44)
    at async handleMessage (node:internal/modules/esm/worker:168:18) {
  code: 'ERR_UNKNOWN_MODULE_FORMAT'
}

Node.js v20.5.1

I tried to change to:

"imports": {
  "#eql": "./eql/index.mjs"
},

Then, error is

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/foxpro/craft/sferadel/dev/api/eql/index.mjs' imported from /home/foxpro/craft/sferadel/dev/api/user/user.mts

It's closed circle. Am I doing it in a wrong way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant