WiseLibs / better-sqlite3

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

Uncaught TypeError:Cannot read properties od null(reading 'access‘) at node_modules/better-sqlite3/lib/methods/backup.js #1189

Closed loveStef closed 3 weeks ago

loveStef commented 1 month ago

Hi better-sqlite3! I'm new here. My project use electron,viteandvue3, now I want use better-sqlite3 as datadase. When I try to use import {Todo} from './todo'. Todo is a Class which has some CRUD function relateded to sqlite db. The Console has some error and my app become white Screen. image

some information my node.js version is 20.13.1, I use windows11

`"dependencies": {
    "better-sqlite3": "^10.0.0",
    "node-gyp": "^10.1.0",
    "pinia": "^2.1.7",
    "vue": "^3.4.21",
    "vue-router": "^4.3.0"
  },
  "devDependencies": {
    "@rushstack/eslint-patch": "^1.8.0",
    "@tsconfig/node20": "^20.1.4",
    "@types/jsdom": "^21.1.6",
    "@types/node": "^20.12.5",
    "@vitejs/plugin-vue": "^5.0.4",
    "@vitejs/plugin-vue-jsx": "^3.1.0",
    "@vue/eslint-config-prettier": "^9.0.0",
    "@vue/eslint-config-typescript": "^13.0.0",
    "@vue/test-utils": "^2.4.5",
    "@vue/tsconfig": "^0.5.1",
    "cross-env": "^7.0.3",
    "cypress": "^13.7.2",
    "electron": "^30.0.8",
    "electron-builder": "^24.13.3",
    "electron-rebuild": "^3.2.9",
    "eslint": "^8.57.0",
    "eslint-plugin-cypress": "^2.15.1",
    "eslint-plugin-vue": "^9.23.0",
    "jsdom": "^24.0.0",
    "npm-run-all2": "^6.1.2",
    "prettier": "^3.2.5",
    "start-server-and-test": "^2.0.3",
    "typescript": "~5.4.0",
    "vite": "^5.2.8",
    "vite-plugin-vue-devtools": "^7.0.25",
    "vitest": "^1.4.0",
    "vue-tsc": "^2.0.11"
  }`
neoxpert commented 1 month ago

The only reference to access within backup.js is found within the import section:

https://github.com/WiseLibs/better-sqlite3/blob/6acc3fcebe469969aa29319714b187a53ada0934/lib/methods/backup.js#L1-L6

So it seems that NodeJS' fs module could not be resolved. If you are tyring to load that module within the renderer, you would need to enable NodeJS for the BrowserWindow instance (be careful with that, if you are loading external resources). If this is happening within the main process, something within the build / bundeling setup seems to be off.

mceachen commented 3 weeks ago

Given that OP didn't reply, @neoxpert 's explanation is plausible. Closing.