Using Esbuild to bundle a project upon a prepublishOnly script:
"esbuild src/index.ts --platform=node --outfile=dist/index.js --bundle --minify --define:process.env.NODE_ENV=\"production\""
gettting these errors:
> node_modules/commander/lib/command.js: error: Could not resolve "node:child_process" (mark it as external to exclude it from the bundle)
2 │ const childProcess = require('node:child_process');
╵ ~~~~~~~~~~~~~~~~~~~~
> node_modules/commander/lib/command.js: error: Could not resolve "node:path" (mark it as external to exclude it from the bundle)
3 │ const path = require('node:path');
1
*NOTE: You’ll need to see the repository to get the full picture here: https://github.com/danporeda/jbook
The error occurred with:
commander version ^12.1.0.
ESBuild version 0.8.26.
Running the build script with these versions caused the error.
Changing commander to version 11.0.0 solved the issue.