vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
66.81k stars 6k forks source link

dependency exports field has incorrect string value #3250

Closed ar53n closed 3 years ago

ar53n commented 3 years ago

Describe the bug

Problem with package exports field and deep path import. Some packages can use string in this field.

https://github.com/vitejs/vite/blob/61ea32056048e902ca69d88e1b0a2d21660dae2a/packages/vite/src/node/plugins/resolve.ts#L640-L651

Reproduction

  1. Install package @tabler/icons
  2. Import svg file import settingsUrl from "@tabler/icons/icons/settings.svg?url";
  3. Build app

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
    Memory: 135.72 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    npm: 7.8.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 90.0.4430.93
    Firefox: 87.0
    Safari: 13.1.2
  npmPackages:
    vite: ^2.2.4 => 2.2.4 

Used package manager: npm

Logs

 vite:vite-plugin-svelte transform returns css for /src/App.svelte +0ms
[vite:resolve] Package subpath 'undefined' is not defined by "exports" in /Users/my/Documents/my-svelte-app/node_modules/@tabler/icons/package.json.
error during build:
Error: Package subpath 'undefined' is not defined by "exports" in /Users/my/Documents/my-svelte-app/node_modules/@tabler/icons/package.json.
    at resolveDeepImport (/Users/my/Documents/my-svelte-app/node_modules/vite/dist/node/chunks/dep-2c03f3f9.js:32159:19)
    at tryNodeResolve (/Users/my/Documents/my-svelte-app/node_modules/vite/dist/node/chunks/dep-2c03f3f9.js:31941:11)
    at Object.resolveId (/Users/my/Documents/my-svelte-app/node_modules/vite/dist/node/chunks/dep-2c03f3f9.js:31825:28)
    at /Users/my/Documents/my-svelte-app/node_modules/rollup/dist/shared/rollup.js:18863:25

Before submitting the issue, please make sure you do the following

sodatea commented 3 years ago

@tabler/icons doesn't have icons/settings.svg specified in their exports field. So it is hidden from external users. Vite is working as expected.

The error message has been improved in the latest version, too:

 > node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:32135:7: error: [plugin: vite:dep-scan] Missing "./icons/settings.svg?url" export in "@tabler/icons" package
github-actions[bot] commented 3 years ago

This issue gets locked because it has been closed for more than 14 days.