FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 922 forks source link

[esinstall] "global is not defined" should hint user about `--polyfillNode` option #1094

Open FredKSchott opened 4 years ago

FredKSchott commented 4 years ago

Original Discussion: Follow up from https://github.com/pikapkg/snowpack/discussions/1085 /cc @briwa

This is a follow up to an issue raised by @briwa, where the solution to "global is not defined" was not obvious. We should be able to detect this either ahead of time or inside the onwarn handler, and raise a warning that include info on how to resolve with this flag/config option.

JennieJi commented 4 years ago

Hi @FredKSchott , I find this seems has been done in the rollup-plugin-catch-unresolved, and throws when running snowpack dev with this nice error printed like this:

snowpack

▼ Console

[snowpack] installing dependencies...
[snowpack] ../../../node_modules/node-builtin-pkg/entrypoint.js
   Module "path" (Node.js built-in) is not available in the browser. Run Snowpack with --polyfill-node to fix.
[snowpack] Install failed.

error Command failed with exit code 1.

But in snowpack build it is not catched, and passing normally:

yarn snowpack build
yarn run v1.22.4
$ /Users/jennie.ji/Projects/snowpack/node_modules/.bin/snowpack build
[snowpack] ! building source…
[snowpack] ✔ build complete [0.02s]
[snowpack] installing dependencies...
[snowpack] ! verifying build...
[snowpack] ✔ verification complete
[snowpack] ! writing build to disk...
[snowpack] ✔ build complete [0.02s]
[snowpack] ▶ Build Complete!

Which seems just because the dev command is wrapped by a try catch but build does not. Shall I try to add try catch wrapping the whole build process? Not sure what is the impact...