nodejs/node-addon-examples

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

SurienDG opened this issue · 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.

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 can you submit a PR for that change?

@mhdawson Sure thing 😀. I added one here: nodejs/node-addon-api#1001

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