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

Module type declaration not found #21

Closed
cinob opened this issue Sep 19, 2023 · 15 comments
Closed

Module type declaration not found #21

cinob opened this issue Sep 19, 2023 · 15 comments
Labels
question Further information is requested

Comments

@cinob
Copy link

cinob commented Sep 19, 2023

When importing barcode-detector/pure or barcode-detector/side-effects ts warns that the module or its corresponding type declaration cannot be found.
I'm not sure if this is because of my local ts environment or something else.

@Sec-ant
Copy link
Owner

Sec-ant commented Sep 19, 2023

Can you share your repo or reproduce it in stackblitz or codepen?

@cinob
Copy link
Author

cinob commented Sep 19, 2023

It's just a local editor error message.
There is no problem to use.

@Sec-ant
Copy link
Owner

Sec-ant commented Sep 19, 2023

Not sure if this is related, but subpath import requires Node16, NodeNext or Bundler (I believe) as the moduleResolution in your tsconfig: microsoft/TypeScript#44848 (comment)

If the config looks good, sometimes you'll have to restart the ts server to clear its error messages, in vscode.

And if you are sure this is not a problem of this repo, would you close this issue?

@cinob
Copy link
Author

cinob commented Sep 19, 2023

Other third-party subpath packages I've used have normal type hints, and I've tried to configure this to make the subpath package type hints work.
I'm not sure anyone else has the same problem.

@Sec-ant
Copy link
Owner

Sec-ant commented Sep 19, 2023

Thanks for your input.

exports field should be supported in TypeScript ^4.7, and it will automatically look for corresponding declaration files once it resolves the .js entry files: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#:~:text=The%20new%20support,types%22%20import%20condition.

So I don't think setting the declaration files path is necessary, and setting typesVersions with es module d.ts paths seems strange because this is a dual module package which supports both es and cjs module at the same time.

If this error bothers you, please share me a reproducible repo so I can properly fix it.

@Sec-ant Sec-ant added the question Further information is requested label Sep 19, 2023
@cinob
Copy link
Author

cinob commented Sep 20, 2023

All projects that directly import the 'barcode-detector/pure' package will report this error.
For example, in vue-qrcode-reader here

@Sec-ant
Copy link
Owner

Sec-ant commented Sep 20, 2023

Working fine on my side, what's your Typescript version?

image

@cinob
Copy link
Author

cinob commented Sep 20, 2023

5.2.2
image
Here's a repo

@Sec-ant
Copy link
Owner

Sec-ant commented Sep 20, 2023

I've made a PR in your repo to solve this issue. It's because nuxt is using node as the default moduleResolution strategy. bundler is recommended for future projects.

refs:

@cinob
Copy link
Author

cinob commented Sep 20, 2023

Thank you very much, this was solved nicely by setting moduleResolution: bundler

@cinob cinob closed this as completed Sep 20, 2023
@ollema
Copy link

ollema commented Dec 3, 2023

@Sec-ant do you know if there is a way to make this work with moduleResolution being set to node?

I have to use node because I am using SvelteKit which is configured to use node and does not work with bundler for now (from what I can tell at least)

@ollema
Copy link

ollema commented Dec 3, 2023

nevermind, this will not be an issue soon:
sveltejs/kit#11160

@Sec-ant
Copy link
Owner

Sec-ant commented Dec 3, 2023

@ollema Could you please provide a minimal setup so I can take a look?

@ollema
Copy link

ollema commented Dec 3, 2023

@ollema Could you please provide a minimal setup so I can take a look?

no need - this will be fixed in SvelteKit 2.0

@ollema
Copy link

ollema commented Dec 15, 2023

just a heads up for any SvelteKit users that might stumble upon this thread - SvelteKit 2.0 was just released and now this package works great out of the box!

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

No branches or pull requests

3 participants