biscuit-auth / biscuit-wasm

WebAssembly wrapper for Biscuit authorization tokens

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

importing with rollup

Geal opened this issue · comments

I have tried for a while to get it to work with rollup and still get some issues. Here's the current code I have:

import nodeResolve from '@rollup/plugin-node-resolve';
import { wasm } from '@rollup/plugin-wasm';

const sourceDir = '.';
const outputDir = 'dist';

export default {
  input: 'index.js',
  output: {
    dir: './rollup-dist',
    format: 'esm'
  },
  plugins: [
    nodeResolve({ browser: true }),
    wasm()
  ]
};

It returns a bunch of errors of this kind and generates a bundled file full of undefined placeholders:

../../module/biscuit_bg.js
memory is not exported by ../../module/biscuit_bg.wasm
2195: 
2196: export function __wbindgen_memory() {
2197:     const ret = wasm.memory;
                           ^
2198:     return addHeapObject(ret);
2199: };
../../module/biscuit.js
__wbindgen_start is not exported by ../../module/biscuit_bg.wasm
1: import * as wasm from "./biscuit_bg.wasm";
2: export * from "./biscuit_bg.js";
3: wasm.__wbindgen_start();

What's weird here is that we have a working rollup config for the website, but maybe that one works because the package is built differently?

Seems to be related to rollup/plugins#617
I tried to --target web when building the wasm package and the generated code is back, but It now throws this error:

❯ rollup -c

index.js → ./rollup-dist...
[!] Error: Identifier 'init' has already been declared
../biscuit-wasm/module/biscuit.js (2190:15)
2188: }
2189: 
2190: async function init(input) {
                     ^
2191:     if (typeof input === 'undefined') {
2192:         input = new URL('biscuit_bg.wasm', import.meta.url);
Error: Identifier 'init' has already been declared
    at error (/home/ptondereau/Code/rust/biscuit-js-example/node_modules/rollup/dist/shared/rollup.js:198:30)
    at Module.error (/home/ptondereau/Code/rust/biscuit-js-example/node_modules/rollup/dist/shared/rollup.js:12560:16)
    at Module.tryParse (/home/ptondereau/Code/rust/biscuit-js-example/node_modules/rollup/dist/shared/rollup.js:12937:25)
    at Module.setSource (/home/ptondereau/Code/rust/biscuit-js-example/node_modules/rollup/dist/shared/rollup.js:12842:24)
    at ModuleLoader.addModuleSource (/home/ptondereau/Code/rust/biscuit-js-example/node_modules/rollup/dist/shared/rollup.js:22090:20)