How to solve error "The module ... was compiled against a different Node.js version" when using authenticate-p

admin2025-04-17  3

Similar questions suggest to delete the contents of the node_modules directory and run npm install again or npm rebuild authenticate-pam --update-binary. All of these did not work in my case (Ubuntu 22.04 running Node.js v17.9.1). When starting the application, I always get

Error: The module '.../node_modules/authenticate-pam/

build/Release/authenticate_pam.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 102. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1183:18)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/media/Daten1/Code/GitLab/scanapp/app/index.js:7:13)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  code: 'ERR_DLOPEN_FAILED'
}

I found out [1] that NODE_MODULE_VERSION 102 is the version installed on my system, whereas NODE_MODULE_VERSION 72 is version v12.22.12 (maybe the version the module was originally built against).

How can I solve this issue? Or is there any other method to authenticate my Node app's users using PAM?

[1]

EDIT: Meanwhile I found out that my system had node-gyp installed using APT (while Node itself is installed using Snap), but the version shipped with Ubuntu 22.04 is for Node 12.22.9. So I uninstalled it using APT and added it by running npm install -g node-gyp. Now when I run npm i authenticate-pam, I get an error: "npm ERR! command failed" In the log file I see these lines:

68 verbose stack Error: command failed
68 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
68 verbose stack     at ChildProcess.emit (node:events:527:28)
68 verbose stack     at maybeClose (node:internal/child_process:1090:16)
68 verbose stack     at Socket.<anonymous> (node:internal/child_process:449:11)
68 verbose stack     at Socket.emit (node:events:527:28)
68 verbose stack     at Pipe.<anonymous> (node:net:715:12)
转载请注明原文地址:http://anycun.com/QandA/1744905358a89281.html