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

Trouble importing version 2.1.0 #10

Closed
kasperp opened this issue Jan 7, 2024 · 5 comments · Fixed by #11
Closed

Trouble importing version 2.1.0 #10

kasperp opened this issue Jan 7, 2024 · 5 comments · Fixed by #11

Comments

@kasperp
Copy link

kasperp commented Jan 7, 2024

Hello,

Firstly, I want to express my appreciation for the browserslist-to-esbuild package. It's been very useful in my projects.

Recently, I upgraded to version 2.1.0 and encountered an issue with the import statement in my vite.config.ts file. Here's how I'm using it:

import browserslistToEsbuild from 'browserslist-to-esbuild';

export default defineConfig({
   build: {
    target: browserslistToEsbuild()
  },
});

After the upgrade, the import fails with the error: Cannot find module 'browserslist-to-esbuild' or its corresponding type declarations.

I'm not an expert with NPM packages, but I found that modifying your package.json as shown below resolves the issue:

{
  "name": "browserslist-to-esbuild",
  ...
  "type": "module",
- "exports": {
-   "types": "./src/index.d.ts",
-   "default": "./src/index.js"
- }
+ "exports": {
+   ".": "./src/index.js"
+ },
+ "types": "./src/index.d.ts",
   ...
}

I'm not sure if I should be importing the module differently or if the exports field in package.json needs to be specified differently. Could you please provide some guidance on this? I can help out with a PR with this changes if that helps.

Thank you for your time and assistance.

@marcofugaro
Copy link
Owner

Hello, please share your vite and typescript versions.

@kasperp
Copy link
Author

kasperp commented Jan 7, 2024

Sorry - these are my versions.

"typescript": "5.3.3",
"vite": "5.0.11",

@idleberg
Copy link
Contributor

idleberg commented Jan 8, 2024

I can confirm the issue @kasperp runs into and the fix works for me as well. I have seen other repositories that expose exports.types, but I'm not sure what this is used for (other than providing an import for my-package/types). This is undocumented in both, the npm and Node documentation.

As far as I know, a package manifest should always provide a types / typings key, no matter whether it supplies exports.types or not.

Example project using both, top-level types and export.types:

https://github.com/sveltejs/svelte/blob/main/packages/svelte/package.json#L7

@marcofugaro
Copy link
Owner

Ah yeah export.types is supposed to replace types, but we're not there yet.
Thanks for the fix!

@marcofugaro
Copy link
Owner

Fixed in v2.1.1

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

Successfully merging a pull request may close this issue.

3 participants