node-addon-examples icon indicating copy to clipboard operation
node-addon-examples copied to clipboard

C1083: Cannot open include file: 'napi.h': No such file or directory

Open SurienDG opened this issue 4 years ago • 4 comments

I get an error about not being able to find napi.h on Windows.

This only occurs when I use "include_dirs": ["<!@(node -p \"require('node-addon-api').include_dir\")"] versus "include_dirs": ["<!@(node -p \"require('node-addon-api').include\")"] (I was trying to use the former because in the index.js file it says the latter is deprecated.

The only difference I noticed is that inside the in the index.js file in the repo we have the include path in escaped quotes.

I've tried doing this as an experiment in another bindings repo and I found if I add the quotes to the include path it works versus without.

include: `"${__dirname}"`

versus

 include: `${__dirname}`

(The second one gives the error)

[Edit]: I just tried this on Linux (using WSL) and seems like I have the inverse problem...

fatal error: napi.h: No such file or directory
    4 | #include "napi.h"
      |          ^~~~~~~~
compilation terminated.

SurienDG avatar May 10 '21 01:05 SurienDG

So I found that if we simply change line 3 of index.js to

const include_dir = `"${path.relative('.', __dirname)}"`;

then it works on both platforms. Can we have this change made?

SurienDG avatar May 10 '21 01:05 SurienDG

@SurienDG can you submit a PR for that change?

mhdawson avatar May 14 '21 19:05 mhdawson

@mhdawson Sure thing 😀. I added one here: https://github.com/nodejs/node-addon-api/pull/1001

SurienDG avatar May 15 '21 04:05 SurienDG

@SurienDG thanks. For some reason the PR seems to cause failures across platforms, can you take a look.

mhdawson avatar May 17 '21 14:05 mhdawson