Skip to content

fix(plugin-legacy): add types export #20296

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ocavue
Copy link
Contributor

@ocavue ocavue commented Jun 25, 2025

Description

After updating @vitejs/plugin-legacy to v7.0.0, TypeScript is complaining about not being able to find type declarations:

image

This is because @vitejs/plugin-legacy v7.0.0 removed the "types" field in package.json. Noice that there isn't any information about dist/index.d.ts in v7.0.0 package.json.

@vitejs/plugin-legacy v7.0.0 package.json:

  "exports": "./dist/index.js",

@vitejs/plugin-legacy v6.1.1 package.json:

  "main": "./dist/index.cjs",
  "module": "./dist/index.mjs",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    }
  },

This PR fixes the issue by adding back "types": "./dist/index.d.ts" to package.json. This matches vite@7.0.0's package.json structure.

@ocavue ocavue marked this pull request as ready for review June 25, 2025 14:53
@ocavue ocavue force-pushed the ocavue/plugin-legacy-v7-type branch from fa675b6 to ed7597a Compare June 25, 2025 14:56
@sapphi-red sapphi-red added plugin: legacy p2-edge-case Bug, but has workaround or limited in scope (priority) labels Jun 26, 2025
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript will use exports field and loads the corresponding dts if moduleResolution is set to node16+ or bundler. So this is only needed for moduleResolution: node/node12.
But I'm ok with adding this back.

@bluwy
Copy link
Member

bluwy commented Jun 26, 2025

Wouldn't setting that moduleResolution be incorrect anyways since our engines field already specifies node 20/22? I don't think we have to support that usecase, and pushing to fixing on user end side should also fix other things.

@ocavue
Copy link
Contributor Author

ocavue commented Jun 26, 2025

Well, since vite@7.0.0 still includes the types field in its package.json, I believe it's reasonable to add back types to @vitejs/plugin-legacy.

If the Vite team want to push the community to update/fix their tsconfig.json, it might be more effective to update all Vite packages simultaneously and provide a migration path in the release notes etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) plugin: legacy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants