symlinked node_modules in guest breaks the build with `node-addon-api` dep
This seems to be due to node-gyp's path handling, but it's caused by the symlink from /input/node_modules to /home/node/app/node_modules.
I have a local setup (here running in the prebuild/linux-arm64 container) where I've duplicated the /input + copying/symlinking behavior, and this is what happens (this also happens for me in CI, but c&p from my local setup):
node@e560f68801f2:~/app$ npx --no-install prebuildify --arch=arm64 --release
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info find Python using Python version 3.11.2 found at "/usr/bin/python3"
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args '/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/home/node/app/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/tmp/prebuildify/node/20.0.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/tmp/prebuildify/node/20.0.0',
gyp info spawn args '-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/tmp/prebuildify/node/20.0.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/home/node/app',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
Traceback (most recent call last):
File "/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 45, in <module>
sys.exit(gyp.script_main())
^^^^^^^^^^^^^^^^^
File "/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 688, in script_main
return main(sys.argv[1:])
^^^^^^^^^^^^^^^^^^
File "/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 680, in main
return gyp_main(args)
^^^^^^^^^^^^^^
File "/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 665, in gyp_main
generator.GenerateOutput(flat_list, targets, data, params)
File "/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2648, in GenerateOutput
writer.Write(
File "/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 831, in Write
self.fp = open(output_filename, "w")
^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: './build/../../../input/node_modules/node-addon-api/node_addon_api_maybe.target.mk'
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:297:18)
gyp ERR! stack at ChildProcess.emit (node:events:519:28)
gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12)
gyp ERR! System Linux 6.2.0-36-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--target=20.0.0" "--devdir=/tmp/prebuildify/node" "--arch=arm64" "--release"
gyp ERR! cwd /home/node/app
gyp ERR! node -v v20.18.0
gyp ERR! node-gyp -v v10.1.0
The file it's looking for should be in ./build/node_modules/node-addon-api/node_addon_api_maybe.target.mk but it's taking the symlink contents of node_modules (?), turning it into a relative path (??) and glomming it on to the ./build path (???).
I'll be looking in node-gyp code for the faulty path handling, but it might be worth having a mode where node_modules is copied instead of symlinking. If I copy it locally:
node@e560f68801f2:~/app$ npx --no-install prebuildify --arch=arm64 --release
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info find Python using Python version 3.11.2 found at "/usr/bin/python3"
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args '/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/home/node/app/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/tmp/prebuildify/node/20.0.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/tmp/prebuildify/node/20.0.0',
gyp info spawn args '-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/tmp/prebuildify/node/20.0.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/home/node/app',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/node/app/build'
TOUCH Release/obj.target/node_modules/node-addon-api/node_addon_api_except.stamp
CC(target) Release/obj.target/tree_sitter_typescript_binding/typescript/src/parser.o
CC(target) Release/obj.target/tree_sitter_typescript_binding/typescript/src/scanner.o
CC(target) Release/obj.target/tree_sitter_typescript_binding/tsx/src/parser.o
CC(target) Release/obj.target/tree_sitter_typescript_binding/tsx/src/scanner.o
CXX(target) Release/obj.target/tree_sitter_typescript_binding/bindings/node/binding.o
SOLINK_MODULE(target) Release/obj.target/tree_sitter_typescript_binding.node
COPY Release/tree_sitter_typescript_binding.node
make: Leaving directory '/home/node/app/build'
gyp info ok
node@e560f68801f2:~/app$ ls build/node_modules/node-addon-api/node_addon_api_maybe.target.mk
build/node_modules/node-addon-api/node_addon_api_maybe.target.mk
@toshok did you find a solution to this issue? I am running into the same error.
https://github.com/prebuild/prebuildify-cross/pull/24