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

Types could not be resolved when tsconfig moduleResolution is bundler/node16+ #103

Open
3bl3gamer opened this issue Dec 6, 2024 · 0 comments

Comments

@3bl3gamer
Copy link

3bl3gamer commented Dec 6, 2024

What version of this package are you using?

[email protected]
[email protected]

What operating system, Node.js, and npm version?

OS: Arch Linux
Node.js: v23.1.0
npm: 10.9.0

What happened?

Could not find a declaration file for module 'teaful'. '/tmp/t/node_modules/teaful/dist/index.modern.js' implicitly has an 'any' type.
  There are types at '/tmp/t/node_modules/teaful/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'teaful' library may need to update its package.json or typings.ts(7016)

when trying to import package with moduleResolution set to bundler/node16/nodenext.

index.ts:

import createStore from "teaful"

tsconfig.json:

{
	"compilerOptions": {
		"strict": true,
		"target": "ESNext",
		"moduleResolution": "bundler",
	},
}

Import will work correctly with moduleResolution:node (or alias node10), but it should be used with node.js versions before v10 (according to TypeScript doc).

There will be no error without strict:true, but createStore will has no types as well.

What did you expect to happen?

According to TS doc, moduleResolution specifies the module resolution strategy:

  • 'node16' or 'nodenext' for modern versions of Node.js.
  • 'bundler' for use with bundlers.

So teaful should be importable that way.

Looks like each export should have it's own declaration file with matching name, i.e. index.d.ts for index.js, index.modern.d.ts for index.modern.js, etc. I have checked, import will work correctly if node_modules/teaful/dist/index.d.ts is copied to node_modules/teaful/dist/index.modern.d.ts.

OR "exports" entries in package.json should have their own "type" field with path to declaration file. I have checked, package.json with this exports works too:

  "exports": {
    "require": "./dist/index.js",
    "default": {
      "default": "./dist/index.modern.js",
      "types": "./dist/index.d.ts"
    }
  },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant