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

export {_default as default} + import x results incorrect for node16 resolution #50067

Closed
JounQin opened this issue Jul 27, 2022 · 1 comment
Closed
Assignees
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@JounQin
Copy link

JounQin commented Jul 27, 2022

Bug Report

🔎 Search Terms

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

reproduction https://github.com/un-ts/lib-boilerplate/blob/main/vitest.config.ts#L8

💻 Code

import autoImport from 'unplugin-auto-import/vite'
import { defineConfig } from 'vitest/config'

export default defineConfig({
  plugins: [
    autoImport({
      imports: 'vitest',
    }),
  ],
  test: {
    coverage: {
      reporter: ['lcov', 'json'],
    },
  },
})

🙁 Actual behavior

vitest.config.ts:6:5 - error TS2349: This expression is not callable.
  Type 'typeof import("/Users/JounQin/Workspaces/GitHub/domiso/node_modules/.pnpm/[email protected]_2rke2oyl5nfm2lrwejsnq3sdfe_zhxiakfykinkigydwrmzev47um/node_modules/unplugin-auto-import/dist/vite")' has no call signatures.

6     autoImport({

🙂 Expected behavior

No error

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jul 28, 2022
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.9.0 milestone Jul 28, 2022
@weswigham
Copy link
Member

weswigham commented Aug 1, 2022

unplugin-auto-import has a broken export map. Their export map defines all their entrypoints as cjs only - they need a nested types entry for both the require and import conditions that points a different files with the correct module format. This is exactly the format confusion issue that arises when you use an incomplete export map.

Instead of

    "./vite": {
      "types": "./dist/vite.d.ts",
      "require": "./dist/vite.js",
      "import": "./dist/vite.mjs"
    },

it should be

    "./vite": {
      "require": { "types": "./dist/vite.d.ts", "default": "./dist/vite.js" },
      "import": { "types": "./dist/vite.d.mts", "default": "./dist/vite.mjs" }
    },

and, naturally, vite.d.mts needs to exist (it can just reexport stuff from vite.d.ts, though!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants