simonbuchan / native-reg

Node addon (native) module to access windows registry in process.
MIT License
21 stars 10 forks source link

0.3.0 fails to install for ia32 #4

Closed cwalther closed 4 years ago

cwalther commented 4 years ago

Trying to install release 0.3.0 from npm with node-v8.16.2-win-x86 (for which no prebuild is included) fails with Error: Cannot find module 'node-addon-api'.

Log ``` X:\node32test>node --version v8.16.2 X:\node32test>node -e console.log(process.arch) ia32 X:\node32test>npm --version 6.12.0 X:\node32test>npm install native-reg s\.staging\node-gyp-build-db3562f8 (1407ms) > native-reg@0.3.0 install X:\node32test\node_modules\native-reg > node-gyp-build X:\node32test\node_modules\native-reg>if not defined npm_config_node_gyp (node "node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild ) module.js:550 throw err; ^ Error: Cannot find module 'node-addon-api' at Function.Module._resolveFilename (module.js:548:15) at Function.Module._load (module.js:475:25) at Module.require (module.js:597:17) at require (internal/module.js:11:18) at [eval]:1:1 at ContextifyScript.Script.runInThisContext (vm.js:50:33) at Object.runInThisContext (vm.js:139:38) at Object. ([eval]-wrapper:6:22) at Module._compile (module.js:653:30) at evalScript (bootstrap_node.js:479:27) gyp: Call to 'node -p "require('node-addon-api').gyp"' returned exit status 1 while in binding.gyp. while trying to load binding.gyp gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (node_modules\npm\node_modules\node-gyp\lib\configure.js:351:16) gyp ERR! stack at emitTwo (events.js:126:13) gyp ERR! stack at ChildProcess.emit (events.js:214:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12) gyp ERR! System Windows_NT 10.0.18362 gyp ERR! command "node.exe" "node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" gyp ERR! cwd X:\node32test\node_modules\native-reg gyp ERR! node -v v8.16.2 gyp ERR! node-gyp -v v5.0.5 gyp ERR! not ok npm WARN enoent ENOENT: no such file or directory, open 'X:\node32test\package.json' npm WARN node32test No description npm WARN node32test No repository field. npm WARN node32test No README data npm WARN node32test No license field. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! native-reg@0.3.0 install: `node-gyp-build` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the native-reg@0.3.0 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Walther\AppData\Roaming\npm-cache\_logs\2019-12-06T07_50_47_256Z-debug.log X:\node32test> ```

I can fix that by moving node-addon-api from devDependencies to dependencies in package.json. It’s a bit of a shame to have another megabyte of dependencies that is not needed in all cases, but at least it doesn’t have any subdependencies.

In addition, the following change would prebuild binaries for both 32- and 64-bit runtimes. It restricts development to environments that have compilers for both of these architectures though, so I leave it up to you whether that is worth it. (And it increases the package size by 60 kB.)

diff --git a/package.json b/package.json
index b34b1e5..f0ed6b0 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,7 @@
     "clean": "rimraf build lib prebuilds",
     "build": "npm run build:js && npm run build:bindings",
     "build:js": "tsc -p src",
-    "build:bindings": "prebuildify --napi --target node@8.12.0",
+    "build:bindings": "prebuildify --napi --target node@8.12.0 --arch x64 && prebuildify --napi --target node@8.12.0 --arch ia32",
     "test": "node test"
   },
   "dependencies": {

By the way, I notice that the 0.3.0 tarball on npm includes the .idea folder, even though it is not mentioned in files in package.json. Any idea what happened there?

simonbuchan commented 4 years ago

Thanks for the excellent investigation!

Hmm I think the .idea folder thing is a yarn bug, it shows up in yarn pack but not npm pack. I'll switch back to .npmignore if that works, otherwise I guess I'm going to have to remember to use npm publish 😕.

Given that we're windows-only and N-API, we have a small, closed set of builds that are valid, ideally just the 32 and 64-bit builds, but I don't really like that the fallback doesn't work. Easy enough to add the 32 bit build for now, 60kB is not much in comparison to other packages, and just disable the post-install. If anyone wants something else (electron builds? They already have a tray API though)

simonbuchan commented 4 years ago

Just published v0.3.1 with included 32-bit build - let me know if it works for you!

cwalther commented 4 years ago

Unfortunately not, on both architectures:

X:\node64test>npm install native-reg

> native-reg@0.3.1 install X:\node64test\node_modules\native-reg
> using prebuildify

'using' is not recognized as an internal or external command,
operable program or batch file.
npm WARN enoent ENOENT: no such file or directory, open 'X:\node64test\package.json'
npm WARN node64test No description
npm WARN node64test No repository field.
npm WARN node64test No README data
npm WARN node64test No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! native-reg@0.3.1 install: `using prebuildify`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the native-reg@0.3.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Walther\AppData\Roaming\npm-cache\_logs\2019-12-06T10_39_24_696Z-debug.log

Does that “using” mean anything to yarn or to a newer npm? It works for me when I just remove the "install": "using prebuildify", line.

simonbuchan commented 4 years ago

🤦‍♂️

simonbuchan commented 4 years ago

Not having an install step would mean it would ignore the prebuilds and try build anyway, in my previous experience, but that seems to be version dependent. so I've used "install": "echo using prebuilds", just to disable the default, in the past. Missed the echo in that build.

I should not be publishing code at 11PM 😴

Just doing some last testing to make sure It's not broken again...

simonbuchan commented 4 years ago

Ok, v0.3.2 should have this fixed for realsies now. 🤞

It seems from my testing npm checks gypfiles: false is set, but yarn ignores that, and will run node-gyp build unless scripts.install is set to a non-empty command. The simplest option is to just echo something sensible.

cwalther commented 4 years ago

Ah, makes sense.

Yep, working fine now. Thanks, goodnight and have a nice weekend!