dyedgreen / deno-sqlite

Deno SQLite module
https://deno.land/x/sqlite
MIT License
409 stars 36 forks source link

Fails when used as a dependency in a node module #230

Closed alexgleason closed 1 year ago

alexgleason commented 1 year ago

I'm using dnt to convert a deno library which depends on deno-sqlite into an npm module. It fails here:

[dnt] Top level await cannot be used when distributing CommonJS/UMD (See deps/deno.land/x/sqlite@v3.7.1/mod.ts 21:1). Please re-organize your code to not use a top level await or only distribute an ES module by setting the 'scriptModule' build option to false.
error: Uncaught (in promise) Error: Build failed due to top level await when creating CommonJS/UMD package.
        throw new Error(
              ^
    at build (https://deno.land/x/dnt@0.34.0/mod.ts:297:15)
    at async file:///home/alex/Projects/strfry-policies/scripts/npm.ts:5:1
dyedgreen commented 1 year ago

Maybe try this: only distribute an ES module by setting the 'scriptModule' build option to false? The top level await is necessary for compiling the required WASM.

If top level await is not an option for you, you can try making your own entry-point mod.ts where you expose an asynchronous „init“ function or similar. (Something like this is done for the browser distribution.)