Menci / vite-plugin-wasm

Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.
MIT License
281 stars 16 forks source link

RollupError: "default" is not exported by "node_modules/..." #31

Closed happysalada closed 1 year ago

happysalada commented 1 year ago

hey, using this and trying to load a wasm file, I'm getting the following stack trace

error during build:
RollupError: "default" is not exported by "node_modules/.pnpm/@dqbd+tiktoken@1.0.7/node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm", imported by "src/routes/+page.server.ts".
    at error (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:2125:30)
    at Module.error (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:13452:16)
    at Module.traceVariable (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:13863:29)
    at ModuleScope.findVariable (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:12418:39)
    at ReturnValueScope.findVariable (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:6966:38)
    at ChildScope.findVariable (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:6966:38)
    at BlockScope.findVariable (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:6966:38)
    at ReturnValueScope.findVariable (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:6966:38)
    at Identifier.bind (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:8116:40)
    at CallExpression.bind (file:///Users/raphael/dev/glad-chat/node_modules/.pnpm/rollup@3.21.5/node_modules/rollup/dist/es/shared/node-entry.js:5735:28)
 ELIFECYCLE  Command failed with exit code 1.

and I'm trying to

import { Tiktoken, init } from "@dqbd/tiktoken/lite/init";
import wasm from "@dqbd/tiktoken/lite/tiktoken_bg.wasm";
import model from "@dqbd/tiktoken/encoders/cl100k_base.json";
             await init((imports) => WebAssembly.instantiate(wasm, imports));
        const encoder = new Tiktoken(
          model.bpe_ranks,
          model.special_tokens,
          model.pat_str
        );

any pointers would be amazing.

Menci commented 1 year ago

Could you please provide a simple project to reproduce it? Thanks.

happysalada commented 1 year ago

Thanks for coming by, here is the repo where the error happens https://github.com/happysalada/glad-chat running a pnpm run build should trigger the error.

Thanks a lot for the maintenance of this plugin!

Menci commented 1 year ago

Explained in https://github.com/Menci/vite-plugin-wasm/issues/33#issuecomment-1574749234.