vercel/pkg

Native asset within node_modules requires absolute path to be included

j0hnm4r5 opened this issue · 4 comments

What version of pkg are you using?

5.8.1

What version of Node.js are you using?

18.16.0

What operating system are you using?

Ubuntu 20.04

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node18

Describe the Bug

When including a native asset from inside the node_modules folder, I need to specify an absolute path. Otherwise the build process throws an UNEXPECTED-15 error.

Expected Behavior

The asset should be able to bundle with a relative path.

To Reproduce

Clone and run j0hnm4r5/pkg-test

Any updates here? cannot run built package with argon2 because of this bug.

If I use node_modules/argon2/lib/binding/napi-v3/*.node in my assets I get:

Error: UNEXPECTED-15
    at readFromSnapshot (pkg/prelude/bootstrap.js:939:16)
    at Object.readSync (pkg/prelude/bootstrap.js:946:12)
    at copyInChunks (pkg/prelude/bootstrap.js:175:21)
    at Object.copyFileSync (pkg/prelude/bootstrap.js:1182:5)
    at copyFolderRecursiveSync (pkg/prelude/bootstrap.js:247:12)
    at copyFolderRecursiveSync (pkg/prelude/bootstrap.js:203:9)
    at copyFolderRecursiveSync (pkg/prelude/bootstrap.js:203:9)
    at copyFolderRecursiveSync (pkg/prelude/bootstrap.js:203:9)
    at process.dlopen (pkg/prelude/bootstrap.js:2232:9)
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1196:18)

If I do use a full path /home/.../node_modules/argon2/lib/binding/napi-v3/argon2.node I get this error:

Error: Cannot find module 'C:\snapshot\<redacted>\node_modules\.pnpm\argon2@0.30.3\node_modules\argon2\lib\binding\napi-v3\argon2.node'
Require stack:
- C:\snapshot\<redacted>\node_modules\.pnpm\argon2@0.30.3\node_modules\argon2\argon2.js
- C:\snapshot\<redacted>\packages\backend\dist\routes\auth.js
- C:\snapshot\<redacted>\packages\backend\dist\routes.js
- C:\snapshot\<redacted>\packages\backend\dist\app.js
- C:\snapshot\<redacted>\packages\backend\dist\index.js
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1951:46)
    at Function.Module._load (node:internal/modules/cjs/loader:787:27)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\snapshot\<redacted>\node_modules\.pnpm\argon2@0.30.3\node_modules\argon2\argon2.js:9:25)
    at Module._compile (pkg/prelude/bootstrap.js:1926:22)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
    at Module.load (node:internal/modules/cjs/loader:988:32

And I have this compilation warnings:

> pkg@5.8.1
> Warning Babel parse has failed: Unexpected token (1:0)
prebuild-install warn install connect ECONNREFUSED 127.0.0.1:80
prebuild-install warn install connect ECONNREFUSED 127.0.0.1:80
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\<redacted>\node_modules\.pnpm\@fastify+swagger-ui@1.9.0\node_modules\@fastify\swagger-ui\static\logo.svg

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

same.