node-addon-examples
node-addon-examples copied to clipboard
node-addon-api cannot be located during npm install
I am having a very strange bug. I am inside the node-addon-api dir of the hello world example and when I try to follow the instructions, I get a failure after command: npm install
essentially it complains that it cannot find node-addon-api when the fline: node -p "require('node-addon-api').include" is executed to get the include dir for the binding.gyp file.
I am including the whole log for reference.
I have no idea why it's not able to find the module, sinc this error persists even when I insttall it directly: npm install node-addon-api
I tried building the n-api dir and it worked no problem: #inside napi dir npm install node-gyp rebuild node ./ 2019-01-12T19_08_43_417Z-debug.log
Hi @SamKacer,
could you try to remove all the folders inside .node-gyp
folder? I think that in Windows the .node-gyp
folder is /Users/your-user/.cache/.node-gyp
, but I'm not sure that this the right path.
After that go to inside the node-addon-api
example and digit: npm install
@NickNaso thank you for your reply. I found my .node-gyp folder under Users\MyUserName.node-gyp
I deleted its contents and ran npm install inside the dir of the example project, but I got the exact same error log.
node-gyp cannot resolve "<!@(node -p "require('node-addon-api').include")" in the binding.gyp file, even though when I run the same command in the command line it returns the include path just fine.
Hi @SamKacer,
is it a problem with only eith node-addon-api example or you experiment something similar with nan
and napi
examples?
If it's your first time with native add-on, maybe you don't have all your environment properly set. For windows I suggest to install all you need with the following commands:
$ npm install --global --production windows-build-tools
See: https://www.npmjs.com/package/node-gyp#option-1
Sorry for the delay in answering you.
@NickNaso napi examples build just fine using the commands.
node addon api builds as well, but I have to write the absolute path to the include file in the binding.gyp file manually. I only have a problem that when node-gyp tries to resolve the include path during the building process it cannot locate node-addon-api, but if the path is written in the binding.gyp file manually, node-gyp executes the rest of the build process without a problem.
@NickNaso thank you for your reply. I found my .node-gyp folder under Users\MyUserName.node-gyp
I deleted its contents and ran npm install inside the dir of the example project, but I got the exact same error log.
node-gyp cannot resolve "<!@(node -p "require('node-addon-api').include")" in the binding.gyp file, even though when I run the same command in the command line it returns the include path just fine.
Have you figured this out yet?
I believe your problem is the lack of escaping quotes. This is my configuration vs yours:
"<!@(node -p \"require('node-addon-api').include\")"
vs "<!@(node -p "require('node-addon-api').include")"
As you might notice yours lacks the \
slashes which are necessary.
@djburkhart thanks for your reply. I havent resolved it yet and I am afraid that is not the issue for me.
Here is what that line looks like in mybinding.gyp:
"<!@(node -p \"require('node-addon-api').include\")"
to make sure that I got the exact set up, I recloned a fresh copy of the repo from the URL https://github.com/nodejs/node-addon-examples
then inside the dir
...\node-addon-examples\1_hello_world\node-addon-api
I ran following command:
npm install
But I still got the same error complaining about not being able to resolve the same include line in binding.gyp. Attaching log for reference. 2019-05-20T11_09_57_279Z-debug.log
I had a similar issue with a different install needing node-addon-api and I resolved it with (note the -g
):
sudo npm install -g node-addon-api
I came here from google after running vue create
with custom setup and getting a cryptic error message relating to this package.
For future self, this can be fixed by using Mocha+chai
instead of Jest
as unit testing framework.
Submitted bug report to vue-cli https://github.com/vuejs/vue-cli/issues/6445