better-sqlite3 icon indicating copy to clipboard operation
better-sqlite3 copied to clipboard

better_sqlite3 was compiled against a different Node.js version using NODE_MODULE_VERSION 115

Open AnotherPillow opened this issue 1 year ago • 10 comments

I have been getting this error for seemingly no reason today. I have tried the following node versions:

  • 20.11.0
  • 20.0.0
  • 18.16.0

I have also tried npm rebuild, rm -rf node_modules/, npm install and everything else I could find. This only started happening today and the error only shows up in VS Code, it doesn't appear when running my application (SvelteKit web app), only in .svelte files on the <style> tags and not in the file where I actually reference better-sqlite3. This is the full error:

The module '\\?\[redacted]\node_modules\better-sqlite3\build\Release\better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 115. This version of Node.js requires
NODE_MODULE_VERSION 116. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

AnotherPillow avatar Jan 21 '24 20:01 AnotherPillow

The required NODE_MODULE_VERSION 116 is related to Electron v26. If you want to use better-sqlite3 within an Electron environment, you need to adjust your project so that the required native module is loaded.

As there are several ways of doing that, which are depending on the overall project setup, a brief overview may be found in the Electron documentation about native node modules.

neoxpert avatar Jan 22 '24 21:01 neoxpert

The required NODE_MODULE_VERSION 116 is related to Electron v26. If you want to use better-sqlite3 within an Electron environment, you need to adjust your project so that the required native module is loaded.

As there are several ways of doing that, which are depending on the overall project setup, a brief overview may be found in the Electron documentation about native node modules.

I am not using electron

AnotherPillow avatar Jan 22 '24 22:01 AnotherPillow

U should check the node versions u are using are same

  • npm install the node version of npm running, the install action will use the NODE_MODULE_VERSION to download the prebuild.
  • the runtime node version.

According to this

 The module '\\?\[redacted]\node_modules\better-sqlite3\build\Release\better_sqlite3.node'
 was compiled against a different Node.js version using
 NODE_MODULE_VERSION 115. This version of Node.js requires
 NODE_MODULE_VERSION 116. Please try re-compiling or re-installing
 the module (for instance, using `npm rebuild` or `npm install`).

you are using 115 (v20) npm install, and 116 (maybe v21) at runtime

> abi.getTarget('115', 'node')
'20.0.0'
> abi.getTarget('116', 'node')
Uncaught Error: Could not detect target for abi 116 and runtime node
    at Object.getTarget (/private/tmp/node_modules/.pnpm/[email protected]/node_modules/node-abi/index.js:62:9)
>

I met same problem for I'm using a .node-version file at runtime, which cause a version mismatch.

AND why this module not switching to Node-API (N-API)

magicdawn avatar Jan 23 '24 08:01 magicdawn

U should check the node versions u are using are same

* `npm install` the node version of npm running, the install action will use the NODE_MODULE_VERSION to download the prebuild.

* the runtime node version.

According to this

 The module '\\?\[redacted]\node_modules\better-sqlite3\build\Release\better_sqlite3.node'
 was compiled against a different Node.js version using
 NODE_MODULE_VERSION 115. This version of Node.js requires
 NODE_MODULE_VERSION 116. Please try re-compiling or re-installing
 the module (for instance, using `npm rebuild` or `npm install`).

you are using 115 (v20) npm install, and 116 (maybe v21) at runtime

> abi.getTarget('115', 'node')
'20.0.0'
> abi.getTarget('116', 'node')
Uncaught Error: Could not detect target for abi 116 and runtime node
    at Object.getTarget (/private/tmp/node_modules/.pnpm/[email protected]/node_modules/node-abi/index.js:62:9)
>

I met same problem for I'm using a .node-version file at runtime, which cause a version mismatch.

AND why this module not switching to Node-API (N-API)

How would I do that? (check the versions are the same)

AnotherPillow avatar Jan 24 '24 18:01 AnotherPillow

How would I do that? (check the versions are the same)

See https://github.com/WiseLibs/better-sqlite3/blob/master/docs/troubleshooting.md -- specifically, delete your node_modules and $HOME/.node-gyp directories, and re-run npm install.

mceachen avatar Jan 24 '24 19:01 mceachen

I have been getting this error for seemingly no reason today. I have tried the following node versions:

  • 20.11.0
  • 20.0.0
  • 18.16.0

I have also tried npm rebuild, rm -rf node_modules/, npm install and everything else I could find. This only started happening today and the error only shows up in VS Code, it doesn't appear when running my application (SvelteKit web app), only in .svelte files on the <style> tags and not in the file where I actually reference better-sqlite3. This is the full error:

The module '\\?\[redacted]\node_modules\better-sqlite3\build\Release\better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 115. This version of Node.js requires
NODE_MODULE_VERSION 116. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

I was also getting same error. In my case, the reason of this error is, i switched node version from 18 to 20.11.0 solution:- you need to update your better-sqlite3 version as well using npm update better-sqlite3

Atulkumar112 avatar Feb 12 '24 12:02 Atulkumar112

I was also getting same error. In my case, the reason of this error is, i switched node version from 18 to 20.11.0 solution:- you need to update your better-sqlite3 version as well using npm update better-sqlite3

Still getting the same issue sadly.

AnotherPillow avatar Feb 12 '24 18:02 AnotherPillow

Can you give more information about the project setup (package.json, run scripts ..) or a minimal reproducible example?

Node NODE_MODULE_VERSION 116 is tied to Electron v25 / v26. It looks like the application is running with a different environment than the one you are installing the project with.

neoxpert avatar Feb 12 '24 19:02 neoxpert

Here's the package.json

{
	"name": "project",
	"version": "0.0.1",
	"private": true,
	"scripts": {
		"dev": "vite dev",
		"build": "vite build",
		"preview": "vite preview",
		"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
		"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
	},
	"devDependencies": {
		"@sveltejs/adapter-auto": "^3.1.1",
		"@sveltejs/kit": "^2.0.0",
		"@sveltejs/vite-plugin-svelte": "^3.0.0",
		"@types/node": "^20.10.4",
		"autoprefixer": "^10.4.16",
		"postcss": "^8.4.32",
		"svelte": "^4.2.7",
		"svelte-check": "^3.6.0",
		"svoast": "^2.4.4",
		"svooltip": "^0.7.8",
		"tailwindcss": "^3.3.6",
		"tslib": "^2.4.1",
		"typescript": "^5.0.0",
		"vite": "^5.0.3"
	},
	"type": "module",
	"dependencies": {
		"@fontsource-variable/jetbrains-mono": "^5.0.19",
		"@fontsource/ubuntu": "^5.0.8",
		"@fortawesome/fontawesome-free": "^6.5.1",
		"@types/better-sqlite3": "^7.6.8",
		"@types/ws": "^8.5.10",
		"better-sqlite3": "^9.3.0",
		"postcss-scss": "^4.0.9",
		"seedrandom": "^3.0.5",
		"socket.io": "^4.7.4",
		"socket.io-client": "^4.7.4",
		"ws": "^8.15.1"
	},
	"engines": {
		"node": ">=18.19.0"
	}
}

Again, it only appears in vscode tooltips. I'm not sure how I could get a minimal reproducible example since it doesn't seem to occur in my other project that uses this library either.

AnotherPillow avatar Feb 12 '24 19:02 AnotherPillow

Well .. VS Code is an Electron based application. If your project is loaded within the context of a VS Code plugin or something like that, the native modules have to match the Electron version.

What you could try is downloading a matching prebuilt of better-sqlite3 and instantiate a Database by passing the absolute path to that module by using the nativeBinding option. Otherwise there would be the option to switch to @vscode/sqlite3 which should be part of VS Code.

neoxpert avatar Feb 12 '24 20:02 neoxpert