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 are not portable error when trying to generate .d.ts files with unplugin packages #322

Open
roninjin10 opened this issue Jul 15, 2023 · 0 comments

Comments

@roninjin10
Copy link

Environment

  • node 18.12.1
  • pnpm 8.6.5
  • typescript 5.1.6
  • unplugin 1.3.2

Reproduction

https://github.com/evmts/evmts-monorepo/blob/main/bundlers/bundler/src/unplugin/index.ts

  1. Check out monorepo
  2. pnpm install
  3. cd bundlers/bundler
  4. npx tsc --emitDeclarationOnly

Describe the bug

When trying to compile unplugin we get a type is not portable error on multiple plugins.

Additional context

This error happens when trying to compile a .d.ts file. Some inferred type within unplugin is private, making it impossible for the .d.ts file to reference it. Because of this this error gets thrown.

As a workaround I cast the vite plugin as a rollup plugin and the webpack plugin as a rsPack plugin.

To fix just need to explicitly type whatever types from vite and webpack are being inferred privately or reexport them.

Logs

src/unplugin/index.ts:55:14 - error TS2742: The inferred type of 'viteFoundry' cannot be named without a reference to '.pnpm/vite@4.3.9_@types+node@20.4.2/node_modules/vite'. This is likely not portable. A type annotation is necessary.

55 export const viteFoundry = foundryUnplugin.vite
                ~~~~~~~~~~~

src/unplugin/index.ts:58:14 - error TS2742: The inferred type of 'webpackFoundry' cannot be named without a reference to '.pnpm/webpack@5.1.0/node_modules/webpack'. This is likely not portable. A type annotation is necessary.

58 export const webpackFoundry =
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