Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot find module 'node-addon-api'" when referencing a library on the local filesystem #2905

Open
clemp6r opened this issue Sep 22, 2023 · 0 comments

Comments

@clemp6r
Copy link

clemp6r commented Sep 22, 2023

I have a project referencing a native module on the local filesystem.

For example:

"dependencies": {
    "hello": "file:../../node-addon-examples/1_hello_world/node-addon-api",
}

When I run npm install in my project, I get an error saying Cannot find module 'node-addon-api'.

The issue does not occur if I run npm install in the folder of the dependency, and then run npm install again in my project.
I tested with three different native librairies and reproduced each time. For one of them I also tested using the npm public registry instead of a local filesystem reference and the issue did not occur: the issue only occurs when using local filesystem paths to reference the library.

I'm not sure which component is responsible for this issue, or whether it is an issue or an expected behavior.

Thanks

  • Node Version: 18.18.0 (npm 9.8.1)
  • Platform: Windows 11
  • Compiler: 16.11.2.50704
  • Module: any module stored on the local filesystem, reproduced here with node-addon-api hello world sample
Verbose output (from npm or node-gyp):
PS C:\Users\Clem\projects\my-project\app> npm install
npm ERR! code 1
npm ERR! path C:\Users\Clem\projects\node-addon-examples\1_hello_world\node-addon-api
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.4.0
npm ERR! gyp info using node@18.18.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.4 found at "C:\Python310\python.exe"
npm ERR! gyp info find VS using VS2019 (16.11.33027.164) found at:
npm ERR! gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn C:\Python310\python.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'C:\\ProgramData\\nvm\\v18.18.0\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'msvs',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\Clem\\projects\\node-addon-examples\\1_hello_world\\node-addon-api\\build\\config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\ProgramData\\nvm\\v18.18.0\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\Clem\\AppData\\Local\\node-gyp\\Cache\\18.18.0\\include\\node\\common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=C:\\Users\\Clem\\AppData\\Local\\node-gyp\\Cache\\18.18.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=C:\\ProgramData\\nvm\\v18.18.0\\node_modules\\npm\\node_modules\\node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\Clem\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\18.18.0\\\\<(target_arch)\\\\node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\Clem\\projects\\node-addon-examples\\1_hello_world\\node-addon-api',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'C:\\Users\\Clem\\projects\\node-addon-examples\\1_hello_world\\node-addon-api\\build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! node:internal/modules/cjs/loader:1080
npm ERR!   throw err;
npm ERR!   ^
npm ERR!
npm ERR! Error: Cannot find module 'node-addon-api'
npm ERR! Require stack:
npm ERR! - C:\Users\Clem\projects\node-addon-examples\1_hello_world\node-addon-api\[eval]
npm ERR!     at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
npm ERR!     at Module._load (node:internal/modules/cjs/loader:922:27)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1143:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:119:18)
npm ERR!     at [eval]:1:1
npm ERR!     at Script.runInThisContext (node:vm:123:12)
npm ERR!     at Object.runInThisContext (node:vm:299:38)
npm ERR!     at node:internal/process/execution:82:21
npm ERR!     at [eval]-wrapper:6:24
npm ERR!     at runScript (node:internal/process/execution:81:62) {
npm ERR!   code: 'MODULE_NOT_FOUND',
npm ERR!   requireStack: [
npm ERR!     'C:\\Users\\Clem\\projects\\node-addon-examples\\1_hello_world\\node-addon-api\\[eval]'
npm ERR!   ]
npm ERR! }
npm ERR!
npm ERR! Node.js v18.18.0
npm ERR! gyp: Call to 'node -p "require('node-addon-api').include"' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (C:\ProgramData\nvm\v18.18.0\node_modules\npm\node_modules\node-gyp\lib\configure.js:325:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:517:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:292:12)
npm ERR! gyp ERR! System Windows_NT 10.0.22621
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\ProgramData\\nvm\\v18.18.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\Clem\projects\node-addon-examples\1_hello_world\node-addon-api
npm ERR! gyp ERR! node -v v18.18.0
npm ERR! gyp ERR! node-gyp -v v9.4.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in: C:\Users\Clem\AppData\Local\npm-cache\_logs\2023-09-22T07_54_48_917Z-debug-0.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant