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

Cannot import wasm as URL from a package which has exports field declared in package.json #6725

Closed
7 tasks done
sapphi-red opened this issue Feb 2, 2022 · 0 comments · Fixed by #7073 or #7098
Closed
7 tasks done

Comments

@sapphi-red
Copy link
Member

sapphi-red commented Feb 2, 2022

Describe the bug

import path from '@sapphi-red/speex-preprocess-wasm/speex.wasm?url';

When writing the code above, the error below happens.

Error: Missing "./speex.wasm?url" export in "@sapphi-red/speex-preprocess-wasm" package

But since ?url is not a node.js spec so I think it should use ./speex.wasm instead of ./speex.wasm?url in exports field.

Reproduction

https://stackblitz.com/edit/js-9rbxxx?file=index.js

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 11.00 GB / 31.93 GB
  Binaries:
    Node: 16.13.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD
    npm: 7.24.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.76)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    vite: ^2.7.13 => 2.7.13

Used Package Manager

npm

Logs

No response

Validations

MadLittleMods added a commit to element-hq/hydrogen-web that referenced this issue Feb 26, 2022
Fix #686
Fix #682

Instead of deleting the whole `target/` directory, leave it alone so the symlink
driving the `npm link`/`yarn link` stays in tact.

Leave Vite builds in their build directories (`/lib-build`/`/asset-build`)
so you can `vite build --watch` to build on local changes and still have a
consisent place to reference in the `package.json` `exports`. Previously,
everything relied on `build.sh` which does a bunch of moving and renaming
and made it hard to rebuild on changes.

Add back support for CommonJS (adding the `package.json` `exports`).

The last piece is making sure the `?url` imports (`import workerPath from 'hydrogen-view-sdk/main.js?url';`)
work still. It looks like this may have just been solved via
vitejs/vite#6725 -> vitejs/vite#7073
(literally 2 days ago) and we just need to wait for the next Vite release 🎉
MadLittleMods added a commit to MadLittleMods/vite that referenced this issue Feb 26, 2022
…rts w/ query

Related to vitejs#6725 which fixed up some cases
like `import deepPath from 'resolve-exports-path/deep.js?url'`
@github-actions github-actions bot locked and limited conversation to collaborators Mar 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
1 participant