Need help installing nbb

it looks like the best way to install an npm package is to use node2nix. Ideally, I would like to not clone the package, but here we are.

I cloned nbb-v0.29 and ran node2nix in the directory. then nix-build.

It almost works but I got this error

shrinking RPATHs of ELF executables and libraries in /nix/store/4v6ndh0xn9m6dhnly83h66hgg81y0vip-node-dependencies-nbb-0.2.9
npm ERR! code ENOENT5minstall executeActionslTree0m
checking for references to /build/ in /nix/store/85j4na3mz5nkv080ybli0cyf3k6j2fiz-node-dependencies-nbb-0.2.9...
npm ERR! syscall chmod
npm ERR! path /nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules/nbb/out/nbb_main.js
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules/nbb/out/nbb_main.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
the symlink /nix/store/4v6ndh0xn9m6dhnly83h66hgg81y0vip-node-dependencies-nbb-0.2.9/bin is broken, it points to /nix/store/4v6ndh0xn9m6dhnly83h66hgg81y0vip-node-dependencies-nbb-0.2.9/lib/node_modules/.bin (which is missing)
rewriting symlink /nix/store/4v6ndh0xn9m6dhnly83h66hgg81y0vip-node-dependencies-nbb-0.2.9/bin to be relative to /nix/store/4v6ndh0xn9m6dhnly83h66hgg81y0vip-node-dependencies-nbb-0.2.9
patching script interpreter paths in /nix/store/4v6ndh0xn9m6dhnly83h66hgg81y0vip-node-dependencies-nbb-0.2.9
checking for references to /build/ in /nix/store/4v6ndh0xn9m6dhnly83h66hgg81y0vip-node-dependencies-nbb-0.2.9...
building '/nix/store/h73y8iddw35zwkqk60wd1ny5c27vxksx-node-shell-nbb-0.2.9.drv'...

npm ERR! A complete log of this run can be found in:
npm ERR!     /build/.npm/_logs/2022-03-20T20_18_16_555Z-debug.log

Not sure how to solve that particular issue, however depending on your goal here you could just use Nix to provide a dev shell with Node, then install Node packages normally (not using node2nix).

If you still want your NPM package installed via Nix, is there any additional info in the /build/.npm/_logs/2022-03-20T20_18_16_555Z-debug.log file?

The debug logfile it tells me to look at doesn’t exist.

I had some poor experience installing via npx on nixos in the past.

I think you can use the --keep-failed flag to preserve those logs.

1 Like

doesn’t seem to work :confused:

It’s a bit confusing since there are a few layers here, the path with /build is spit out by NPM, but you also need the path from nix, see the note: keeping build directory line.

So looks like the log should be in /tmp/nix-build-nbb-0.2.9.drv-1/.npm/_logs.

1 Like

Oh wow. I would have never figured that out.

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/nix/store/rvdwqyys0nj4gw8ryxjpyz256m1wr1xd-nodejs-12.22.9/bin/node',
1 verbose cli   '/nix/store/rvdwqyys0nj4gw8ryxjpyz256m1wr1xd-nodejs-12.22.9/bin/npm',
1 verbose cli   '--offline',
1 verbose cli   '--nodedir=/nix/store/bis4ikxva5b2hw4f0fndhl6fawqxd8w9-node-sources',
1 verbose cli   '--production',
1 verbose cli   'install'
1 verbose cli ]
2 info using npm@6.14.15
3 info using node@v12.22.9
4 verbose npm-session afab73924ae47fcd
5 silly install runPreinstallTopLevelLifecycles
6 silly preinstall nbb@0.2.9
7 info lifecycle nbb@0.2.9~preinstall: nbb@0.2.9
8 silly install loadCurrentTree
9 silly install readLocalPackageData
10 timing stage:loadCurrentTree Completed in 8ms
11 silly install loadIdealTree
12 silly install cloneCurrentTreeToIdealTree
13 timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms
14 silly install loadShrinkwrap
15 timing stage:loadIdealTree:loadShrinkwrap Completed in 2ms
16 silly install loadAllDepsIntoIdealTree
17 silly fetchPackageMetaData error for ink@^3.0.9 request to https://registry.npmjs.org/ink failed: cache mode is 'only-if-cached' but no cached response available.
18 silly fetchPackageMetaData error for react@^17.0.2 request to https://registry.npmjs.org/react failed: cache mode is 'only-if-cached' but no cached response available.
19 silly fetchPackageMetaData error for react-dom@^17.0.2 request to https://registry.npmjs.org/react-dom failed: cache mode is 'only-if-cached' but no cached response available.
20 silly fetchPackageMetaData error for shadow-cljs@^2.15.2 request to https://registry.npmjs.org/shadow-cljs failed: cache mode is 'only-if-cached' but no cached response available.
21 silly fetchPackageMetaData error for source-map-support@^0.5.19 request to https://registry.npmjs.org/source-map-support failed: cache mode is 'only-if-cached' but no cached response available.
22 silly fetchPackageMetaData error for ink@^3.0.9 request to https://registry.npmjs.org/ink failed: cache mode is 'only-if-cached' but no cached response available.
23 silly fetchPackageMetaData error for react@^17.0.2 request to https://registry.npmjs.org/react failed: cache mode is 'only-if-cached' but no cached response available.
24 silly fetchPackageMetaData error for react-dom@^17.0.2 request to https://registry.npmjs.org/react-dom failed: cache mode is 'only-if-cached' but no cached response available.
25 silly fetchPackageMetaData error for shadow-cljs@^2.15.2 request to https://registry.npmjs.org/shadow-cljs failed: cache mode is 'only-if-cached' but no cached response available.
26 silly fetchPackageMetaData error for source-map-support@^0.5.19 request to https://registry.npmjs.org/source-map-support failed: cache mode is 'only-if-cached' but no cached response available.
27 timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 59ms
28 timing stage:loadIdealTree Completed in 62ms
29 silly currentTree nbb@0.2.9
30 silly idealTree nbb@0.2.9
31 silly install generateActionsToTake
32 silly diff-trees filtering actions: includeDev false includeProd true includeOpt true
33 timing stage:generateActionsToTake Completed in 3ms
34 silly diffTrees action count 0
35 silly decomposeActions action count 0
36 silly install executeActions
37 silly doSerial global-install 0
38 verbose correctMkdir /build/.npm/_locks correctMkdir not in flight; initializing
39 verbose lock using /build/.npm/_locks/staging-10ae46fa0dfbef1d.lock for /nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules/nbb/node_modules/.staging
40 silly doParallel extract 0
41 silly doReverseSerial unbuild 0
42 silly doSerial remove 0
43 silly doSerial move 0
44 silly doSerial finalize 0
45 silly doParallel refresh-package-json 0
46 silly doParallel preinstall 0
47 silly doSerial build 0
48 silly doSerial global-link 0
49 silly doParallel update-linked 0
50 silly doSerial install 0
51 silly doSerial postinstall 0
52 verbose unlock done using /build/.npm/_locks/staging-10ae46fa0dfbef1d.lock for /nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules/nbb/node_modules/.staging
53 timing stage:executeActions Completed in 30ms
54 timing stage:rollbackFailedOptional Completed in 0ms
55 silly install runPostinstallTopLevelLifecycles
56 silly build nbb@0.2.9
57 info linkStuff nbb@0.2.9
58 silly linkStuff nbb@0.2.9 has /nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules as its parent node_modules
59 verbose linkBins [
59 verbose linkBins   { nbb: 'out/nbb_main.js' },
59 verbose linkBins   '/nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules/.bin',
59 verbose linkBins   false
59 verbose linkBins ]
60 verbose stack Error: ENOENT: no such file or directory, chmod '/nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules/nbb/out/nbb_main.js'
61 verbose cwd /nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules/nbb
62 verbose Linux 5.10.102
63 verbose argv "/nix/store/rvdwqyys0nj4gw8ryxjpyz256m1wr1xd-nodejs-12.22.9/bin/node" "/nix/store/rvdwqyys0nj4gw8ryxjpyz256m1wr1xd-nodejs-12.22.9/bin/npm" "--offline" "--nodedir=/nix/store/bis4ikxva5b2hw4f0fndhl6fawqxd8w9-node-sources" "--production" "install"
64 verbose node v12.22.9
65 verbose npm  v6.14.15
66 error code ENOENT
67 error syscall chmod
68 error path /nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules/nbb/out/nbb_main.js
69 error errno -2
70 error enoent ENOENT: no such file or directory, chmod '/nix/store/s7r1l7vl3hpa4m5a1z2rbnqx1iq92zmn-nbb-0.2.9/lib/node_modules/nbb/out/nbb_main.js'
71 error enoent This is related to npm not being able to find a file.
72 verbose exit [ -2, true ]

Wonder what all that silly stuff is.

No idea what all the silly stuff is, but looking at nbb it’s not really an npm package. It just has a package.json. See here.

The binary it’s trying to link here does indeed not exist. As-is, the package.json doesn’t do anything, except link a nonexistent file. The way this is packaged is apparently to first run bb on the repository, which produces the out directory, and then to run an npm publish that uploads artifacts that don’t even exist in the source.

It’s… Something. I’m sure there are better ways to actually hook build commands into your package.json, but the project isn’t doing that. I’ve never packaged anything with bb, so I can’t help untangle the build, but it clearly manages everything from dependencies to building the software, so node2nix won’t do anything for you here.

2 Likes

yeah, you’re right.

           (do (apply clojure (wrap-cmd "-M -m shadow.cljs.devtools.cli --force-spawn release modules")
                      *command-line-args*)
               (spit "out/nbb_core.js"
                     (clojure.string/replace (slurp "out/nbb_core.js") (re-pattern "self") "globalThis"))
               (spit "out/nbb_main.js"
                     (str "#!/usr/bin/env node\n\n" (slurp "out/nbb_main.js")))
               (shell "chmod +x out/nbb_main.js")
               (run! fs/delete (fs/glob "out" "**.map")))

It looks like out/nbb_main.js is the thing. There is no binary - it’s just minified js with a shebang.

For this to work with nix I would probably have to submit a PR to the project. :thinking:

It works fine locally like this, but the way it pulls dependencies … I’m not sure. Looks like maven.

1 Like

For now if you’re just trying to get it to run, this appears to work: nix-shell -p nodejs --run "npm install nbb && node_modules/.bin/nbb"

1 Like