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

"No matching export" for disabled imports #14628

Closed
7 tasks done
edde746 opened this issue Oct 15, 2023 · 1 comment
Closed
7 tasks done

"No matching export" for disabled imports #14628

edde746 opened this issue Oct 15, 2023 · 1 comment
Labels
bug: upstream Bug in a dependency of Vite p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@edde746
Copy link

edde746 commented Oct 15, 2023

Describe the bug

The webtorrent package has multiple imports that should be disabled when ran in the browser (browser field in package.json), Vite, however just errors when building as it still tries to import the disabled imports.

Reproduction

https://stackblitz.com/edit/vitejs-vite-85pdcs

Steps to reproduce

Install and import webtorrent

System Info

System:
    OS: macOS 13.5.2
    CPU: (8) arm64 Apple M1
    Memory: 208.34 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.0.0 - ~/.nvm/versions/node/v18.0.0/bin/node
    Yarn: 1.22.18 - /usr/local/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.0.0/bin/npm
    pnpm: 8.6.12 - ~/.nvm/versions/node/v18.0.0/bin/pnpm
  Browsers:
    Brave Browser: 117.1.58.135
    Chrome: 118.0.5993.70
    Safari: 16.6
  npmPackages:
    vite: ^4.4.11 => 4.4.11

Used Package Manager

npm

Logs

Click to expand!
~/projects/vitejs-vite-85pdcs
❯ npm run build --debug

> vite-starter@0.0.0 build
> vite build

vite v4.4.11 building for production...
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/webtorrent/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/create-torrent/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/parse-torrent/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/webtorrent/lib/torrent.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
Module "node_modules/webtorrent/lib/torrent.js" tried to import "node_modules/webtorrent/package.json" with "type": "json" assertions, but it was already imported elsewhere with no assertions. Please ensure that import assertions for the same module are always consistent.
[plugin:vite:resolve] Module "crypto" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/bittorrent-protocol/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
Module "node_modules/webtorrent/lib/webconn.js" tried to import "node_modules/webtorrent/package.json" with "type": "json" assertions, but it was already imported elsewhere with no assertions. Please ensure that import assertions for the same module are always consistent.
[plugin:vite:resolve] Module "crypto" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/bittorrent-dht/client.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "util" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/k-rpc/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "dgram" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/k-rpc-socket/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "net" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/k-rpc-socket/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "dns" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/k-rpc-socket/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "util" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/k-rpc-socket/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "buffer" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-85pdcs/node_modules/safe-buffer/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
✓ 168 modules transformed.
✓ built in 598ms
"Client" is not exported by "__vite-browser-external", imported by "node_modules/webtorrent/index.js".
file: /home/projects/vitejs-vite-85pdcs/node_modules/webtorrent/index.js:6:9
4: import createTorrent, { parseInput } from 'create-torrent'
5: import debugFactory from 'debug'
6: import { Client as DHT } from 'bittorrent-dht' // browser exclude
            ^
7: import loadIPSet from 'load-ip-set' // browser exclude
8: import parallel from 'run-parallel'
error during build:
RollupError: "Client" is not exported by "__vite-browser-external", imported by "node_modules/webtorrent/index.js".
    at error (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:2312:30)
    at Module.error (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:13770:16)
    at Module.traceVariable (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:14200:29)
    at ModuleScope.findVariable (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:12640:39)
    at ChildScope.findVariable (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:7149:38)
    at ClassBodyScope.findVariable (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:7149:38)
    at ChildScope.findVariable (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:7149:38)
    at FunctionScope.findVariable (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:7149:38)
    at ChildScope.findVariable (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:7149:38)
    at Identifier.bind (/home/projects/vitejs-vite-85pdcs/node_modules/rollup/dist/es/shared/node-entry.js:8344:40)

Validations

@sapphi-red sapphi-red added bug: upstream Bug in a dependency of Vite p3-minor-bug An edge case that only affects very specific usage (priority) labels Oct 18, 2023
@sapphi-red
Copy link
Member

sapphi-red commented Oct 18, 2023

After upgrading Vite to 5.0.0-beta.10, it worked. It seems this was a bug in esbuild (evanw/esbuild#3367) and was fixed in 0.19.3.
https://github.com/evanw/esbuild/blob/main/CHANGELOG.md#0195:~:text=Fix%20browser%20%2B,for%20named%20imports.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants