vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.1k stars 288 forks source link

Failed build process, for required npm-check-updates #582

Open uruha opened 4 years ago

uruha commented 4 years ago

Hi !, I have a question about building ncc πŸ₯Ί.

Currently, I'm developing github-actions that uses npm-check-updates, but apparently when I build index.js that requires npm-check-updates, I get the following error Appears and I cannot output.

γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ 2020-08-25 13 37 34 (Is node-gyp involved? ? ? πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”οΌ‰

Is there any correspondence or setting that we have to do? Is the node version affected? ? ? This build also had a similar error with the TypeScript version.

Verification please!

πŸ‘‰ PR currently supported

privatenumber commented 3 years ago

Encountered a similar error:

ncc: Version 0.25.1
ncc: Compiling file index.js
 62kB  dist/pre/index.js
 70kB  dist/pre/index.js.map
122kB  dist/pre/sourcemap-register.js
184kB  [548ms] - ncc 0.25.1

> pkg-size-action@0.0.0-semantic-release build:main /Users/privatenumber/gits/action
> ncc build -s  -o dist/main src/index.js && :

ncc: Version 0.25.1
ncc: Compiling file index.js
Error: Module parse failed: Unexpected token (47:25)
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",
|     }),
|     stdioString,
    at /Users/privatenumber/gits/action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:1:3258160
    at /Users/privatenumber/gits/action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:1:2210952
    at eval (eval at create (/Users/privatenumber/gits/action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:1:1140142), <anonymous>:11:1)

I identified that this was caused by @npmcli/run-script/lib/make-spawn-args.js:5 doing require.resolve('node-gyp/bin/node-gyp.js').

I fixed this by externalizing @npmcli/run-script:

ncc build -s --external='@npmcli/run-script' -o dist/main src/index.js

and adding @npcli/runscript and its dependencies to git.

PS, I recommend copy-pasting the error message instead of screen-shotting it so that people searching for this same error can find this issue.

StephenMP commented 2 years ago

@privatenumber

and adding @npcli/runscript and its dependencies to git

How exactly did you do this?

privatenumber commented 2 years ago

Sorry this was a long time ago and I don't remember this specific problem.

However, I do remember I realized ncc is not a requirement for developing GitHub Actions and just using Rollup is a lot easier and faster: https://github.com/pkg-size/action/blob/develop/rollup.config.js

StephenMP commented 2 years ago

@privatenumber Yea, I've tried rollup and could never get it to work. I have referenced your rollup config as well with no luck 🀷 Thanks for the reply though, appreciate it :)