node-java icon indicating copy to clipboard operation
node-java copied to clipboard

node-gyp rebuild fails. fatal error: 'jni_md.h' file not found on OSX 10.11.5

Open gnizhak opened this issue 8 years ago • 6 comments

We use node-tika for our project and it's only dependency is node-java. Last week npm install started failing to an error during node-gyp rebuild

> [email protected] install /Users/gnizhak/redacted/node_modules/java
> node-gyp rebuild

  CXX(target) Release/obj.target/nodejavabridge_bindings/src/java.o
In file included from ../src/java.cpp:1:
In file included from ../src/java.h:7:
/Users/gnizhak/.jenv/versions/1.7/include/jni.h:45:10: fatal error: 'jni_md.h' file not found
#include "jni_md.h"

1 error generated.
make: *** [Release/obj.target/nodejavabridge_bindings/src/java.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:100:13)
gyp ERR! stack     at ChildProcess.emit (events.js:185:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 15.5.0
gyp ERR! command "/usr/local/Cellar/node/5.7.1/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/gnizhak/redacted/node_modules/java

gyp ERR! node -v v5.7.1
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok
npm WARN install:[email protected] [email protected] install: `node-gyp rebuild`
npm WARN install:[email protected] Exit status 1

as you can see from the error message I use jenv to manage my java version but the issue appears on both java 1.7 and 1.8. My JAVA_HOME is thus set /Users/gnizhak/.jenv/versions/1.7 or 1.8 Both JDK installations are Oracle Java and I do not have java 1.6 installed.

xcode-select version 2343 and xcode version 7.3.1 (so gcc says Apple LLVM 7.3.0)

I'm not really in on how the java includes folder is setup on Oracle Java I tried to do some digging and found that /Library/Java/JavaVirtualMachines/{jdk_version}/Contents/Home/include does not contain jni_md.h directly but instead has a subfolder /Library/Java/JavaVirtualMachines/{jdk_version}/Contents/Home/include/darwin where the jni_md.h header file resides.

This issue did not appear in May, but I was away from the project most of June and July so I cannot tell which update may have caused this issue.

I checked out the Info.plist capabilities section referenced in https://github.com/joeferner/node-java/issues/90#issuecomment-45613235 and found that 1.8 already had the capability there and adding that to 1.7 did not resolve the issue.

My colleague with OSX 10.10.5 with xcode-select 2339/xcode 7.2.1 had no such issue.

gnizhak avatar Jul 28 '16 11:07 gnizhak

I'm having the same issue. Also using jenv. Is it possible it's a problem with jenv?

tandrewnichols avatar Oct 11 '16 15:10 tandrewnichols

I am having the same issue when I tried to use the "jabba" java environment manager. Any updates on this issue?

owendall avatar Apr 05 '17 21:04 owendall

@gnizhak Have you figured out a solution for this? I have the same issue, managing java versions using jabba and when installing it fails. cc: @owendall @tandrewnichols

cksachdev avatar Jan 08 '19 09:01 cksachdev

I ended up giving up on jenv and installing different sdks independently. So it has to be the way the jenv/jabba handles the paths on the dependencies.

gnizhak avatar Jan 08 '19 10:01 gnizhak

This is an issue I think for all conformant non-Oracle JDKs at least since 11 on macOS, because jni_md.h is located in /include/darwin

doctorpangloss avatar Jul 24 '20 22:07 doctorpangloss

Mac OS Catalina 10.15.16, using jenv.

I noticed that $JAVA_HOME was not set. Disabling and enabling jenv plugins fixed this.

Per @doctorpangloss's comment copied the file to parent dir:

cp /Users/_username_/.jenv/versions/openjdk64-1.8.0.265/include/darwin/jni_md.h ../

npm install java - voila!

cdolek avatar Aug 12 '20 22:08 cdolek