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

Could not find a declaration file for module 'next-test-api-route-handler'. #908

Closed
jakejones2 opened this issue Oct 31, 2023 · 4 comments
Closed
Assignees
Labels

Comments

@jakejones2
Copy link

The problem

Hi! The import import { testApiHandler } from "next-test-api-route-handler"; gives me the following typescript error:

Could not find a declaration file for module 'next-test-api-route-handler'. '/Users/jakejones/Documents/repos/git/next-test-api-route-handler-import/node_modules/next-test-api-route-handler/dist/esm/index.mjs' implicitly has an 'any' type.
  There are types at '/Users/jakejones/Documents/repos/git/next-test-api-route-handler-import/node_modules/next-test-api-route-handler/dist/types/src/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'next-test-api-route-handler' library may need to update its package.json or typings.ts(7016)

I think the issue is related to prs such as:

Reproduction steps

For basic reproduction: https://github.com/jakejones2/next-test-api-route-handler-import

Suggested solution

A quick fix seems to be changing package.json as follows:

"exports": {
    ".": {
      "types": "./dist/types/src/index.d.ts",
      "import": "./dist/esm/index.mjs",
      "require": "./dist/index.js",
      "default": "./dist/index.js"
    },
    "./package": "./package.json",
    "./package.json": "./package.json"
  },

However, looking at similar pull requests, the problem might require an index.d.mts file. Something like this:

"exports": {
  ".": {
    "import": {
      "types": "./dist/types/src/index.d.mts",
      "default": "./dist/esm/index.mjs",
    },
    "require": {
      "types": "./dist/types/src/index.d.ts",
      "default": "./dist/index.js",
    }
  },
  "./package": "./package.json",
  "./package.json": "./package.json"
},
Additional context

node v.20.4.0
npm v.9.7.2

@jakejones2 jakejones2 added the bug Something isn't working label Oct 31, 2023
@Xunnamius Xunnamius self-assigned this Oct 31, 2023
@Xunnamius
Copy link
Owner

Xunnamius commented Oct 31, 2023

Thanks for this and especially the suggested solutions. Coincidentally, I was checking NTARH on arethetypeswrong a few days ago and pondering solutions.

I'll address this sooner than planned since this is causing problems in the wild. I haven't make the leap to node16 resolution in my TS stack yet, which let this slip under the radar. I'll have to update a few other projects as well 😄

@jakejones2
Copy link
Author

No problem - thanks for picking this up so fast! Seems to be a common issue so hopefully not too much trouble. Best of luck with it!

Xunnamius added a commit that referenced this issue Nov 4, 2023
## [4.0.0-canary.2](v4.0.0-canary.1...v4.0.0-canary.2) (2023-11-04)

#### ⚙️ Build system

* Add core-js polyfills and have mercy on aging node versions ([a9d136b](a9d136b))
* Modernize tooling ([db0223e](db0223e))
* Upgrade typescript-babel toolchain to nodenext ([e457064](e457064)) <sup>closes [#908](https://github.com/Xunnamius/next-test-api-route-handler/issues/908)</sup>
@Xunnamius
Copy link
Owner

🎉 This issue has been resolved in version 4.0.0-canary.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Xunnamius added a commit that referenced this issue Nov 4, 2023
### [3.1.10](v3.1.9...v3.1.10) (2023-11-04)

#### ⚙️ Build system

* Add core-js polyfills and have mercy on aging node versions ([a9d136b](a9d136b))
* Modernize tooling ([db0223e](db0223e))
* Upgrade typescript-babel toolchain to nodenext ([e457064](e457064)) <sup>closes [#908](https://github.com/Xunnamius/next-test-api-route-handler/issues/908)</sup>
@Xunnamius
Copy link
Owner

🎉 This issue has been resolved in version 3.1.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants