WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.53k stars 393 forks source link

Vue3 use better-sqlite3 get error with 'promisify is not a function' #888

Closed Sylor-huang closed 2 years ago

Sylor-huang commented 2 years ago

My package.json is:

 "dependencies": {
    "@element-plus/icons-vue": "^2.0.10",
    "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
    "autoprefixer": "^10.4.12",
    "better-sqlite3": "^7.6.2",
    "element-plus": "^2.2.17",
    "js-cookie": "^3.0.1",
    "moment-mini": "^2.24.0",
    "path": "^0.12.7",
    "postgres": "^3.2.2",
    "tailwindcss": "^3.1.8",
    "unplugin-auto-import": "^0.7.2",
    "unplugin-vue-components": "^0.19.5",
    "vue": "^3.2.25",
    "vue-router": "^4.0.15",
    "vuex": "^4.0.2",
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^2.3.3",
    "sass": "^1.52.1",
    "unplugin-element-plus": "^0.4.0",
    "vite": "^3.1.6"
  }

My node is v16.14.0 and node-gyp had been installed

When I import in js file, and I will get error

import Database from 'better-sqlite3';
// errors

TypeError: promisify is not a function
    at node_modules/better-sqlite3/lib/methods/backup.js (backup.js:6:18)
    at __require2 (chunk-64WWFUG7.js?v=35f1f87c:18:50)
    at node_modules/better-sqlite3/lib/database.js (database.js:72:29)
    at __require2 (chunk-64WWFUG7.js?v=35f1f87c:18:50)
    at node_modules/better-sqlite3/lib/index.js (index.js:2:18)
    at __require2 (chunk-64WWFUG7.js?v=35f1f87c:18:50)
    at dep:better-sqlite3:1:16

I had found a similar issue, but sorry, I don't know how it is resolved

https://github.com/WiseLibs/better-sqlite3/issues/848

Thanks for your help.

Prinzhorn commented 2 years ago

You can't use better-sqlite3 in a browser. You need to do whatever vue tells you how to run server-only code (assuming this is even a SSR project). Like https://github.com/WiseLibs/better-sqlite3/issues/848 said this is not an issue with better-sqlite3.