sql-js / sql.js

A javascript library to run SQLite on the web.

Home Page:http://sql.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use in Vite?

mtdvlpr opened this issue · comments

I am using Nuxt3 with Vite. I have the following code:

import wasmUrl from '@/public/sql-wasm.wasm?url'

const { default: sqljs } = await import('sql.js')
const SQL = await sqljs({
  locateFile: () => wasmUrl,
})

I get the following error:

TypeError: Cannot set properties of undefined (setting 'exports')
    at sql-wasm.js:95:451

When I use the below config I get the error that sqljs is undefined and therefore not a function.

vite: {
  build: {
    rollupOptions: {
      external: [/node_modules\/sql\.js\/dist\/sql-wasm\.js$/],
    },
  },
},

Am I missing something?

This is more a question than an issue, I'm closing it, but feel free to discuss below.

commented

Adding for ref, answered here.