pacote icon indicating copy to clipboard operation
pacote copied to clipboard

[BUG] No possibility to embed pacote in single js file

Open jacek-jablonski opened this issue 3 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

I'm using pacote in my code and trying to pack it inside single js file for GitHub actions using @vercel/ncc or rollup.js. Both methods fail because of node-gyp in inner dependencies.

ncc: Version 0.34.0
ncc: Compiling file index.js into CJS
ncc: Using [email protected] (local user-provided)
Emitting /Users/jacek/Projects/github-workflows-tslibs/actions/node_modules/node-gyp/bin/node-gyp.js for static use in module /Users/jacek/Projects/github-workflows-tslibs/actions/node_modules/@npmcli/run-script/lib/make-spawn-args.js
Skipping asset emission of /Users/jacek/Projects/github-workflows-tslibs/actions/*/package.json for /Users/jacek/Projects/github-workflows-tslibs/actions/node_modules/@npmcli/run-script/lib/make-spawn-args.js as it is outside the package base /Users/jacek/Projects/github-workflows-tslibs/actions/node_modules/@npmcli/run-script
Error: Module parse failed: Unexpected token (29:23)
File was processed with these loaders:
 * ./node_modules/@vercel/ncc/dist/ncc/loaders/empty-loader.js
 * ./node_modules/@vercel/ncc/dist/ncc/loaders/relocate-loader.js
 * ./node_modules/@vercel/ncc/dist/ncc/loaders/shebang-loader.js
You may need an additional loader to handle the result of these loaders.
|     npm_lifecycle_event: event,
|     npm_lifecycle_script: cmd,
>     __webpack_require__.ab + "node-gyp.js",
|   })
| 
    at /Users/jacek/Projects/github-workflows-tslibs/actions/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:37:1770552
    at /Users/jacek/Projects/github-workflows-tslibs/actions/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:37:374702
    at _done (eval at create (/Users/jacek/Projects/github-workflows-tslibs/actions/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:20:75523), <anonymous>:9:1)
    at eval (eval at create (/Users/jacek/Projects/github-workflows-tslibs/actions/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:20:75523), <anonymous>:34:22)

Expected Behavior

It would be nice to be able to compile code with pacote in single js file. The likely solution would be to give up the dependency on node-gyp.

Steps To Reproduce

  1. Use pacote in your code.
  2. Try to compile it into single js file with ncc npx ncc -d build src/assert-prod-version-action.ts
  3. See above error.

Environment

  • npm: 8.11.0
  • Node: 16.16.0
  • OS: Mac OS 12.6
  • platform: x86_64

jacek-jablonski avatar Oct 07 '22 20:10 jacek-jablonski

Same thing is with rollup.js. Single file compiles, but it cannot be executed successfully.

jacek-jablonski avatar Oct 09 '22 13:10 jacek-jablonski

Unfortunately this is not going to be something we can remove from pacote. One of the things npm does when it installs is runs scripts, and if there are no specific install or preinstall scripts, it looks for bindings and builds the dep with node-gyp if it finds them. This is "baked in" to how the npm ecosystem right now and moving from that would mean quite a shift in how things are done, outside the scope of this package itself.

wraithgar avatar Oct 19 '22 14:10 wraithgar