sql-js / sql.js

A javascript library to run SQLite on the web.
http://sql.js.org
Other
12.38k stars 1.05k forks source link

TypeError: Cannot set properties of undefined (setting 'exports') #495

Open xue-chao opened 2 years ago

xue-chao commented 2 years ago

use electron + sqljs error: TypeError: Cannot set properties of undefined (setting 'exports')

ConteMan commented 2 years ago

use electron + sqljs error: TypeError: Cannot set properties of undefined (setting 'exports')

Electron, if in main process, use like const initSqlJs = require('sql.js'), not import initSqlJs from 'sql.js'. In my project, it works.

datduyng commented 2 years ago

Works for me @ConteMan. Thanks a lot !!!

Liting1 commented 2 years ago

You need to copy the./node_modules/sql.js/dist/sql-wasm.wasm file to the directory of your running file If you are using Webpack You should be

New CopyPlugin({  // Copy the binaries required by the SQLite database
    patterns: [{
       from: './node_modules/sql.js/dist/sql-wasm.wasm'
   }]
}),
uservan commented 1 year ago

I use vue3+typescript+sql.js, and I have the same problem, but I always have the error: TypeError: Cannot set properties of undefined (setting 'exports'). I do not know how to slove it.

027xiguapi commented 6 months ago

我对比了一下打包前后的代码,发现了差异 image

027xiguapi commented 6 months ago

webpack.config.js file edit

// webpack.config.js 
module: {
    noParse: /sql.js/,
    rules: [
      {
        test: /\.ts?$/,
        use: {
          loader: 'ts-loader',
          options: { transpileOnly: true },
        },
        exclude: /node_modules/,
      },
    ],
  },