core: Error bundling @oclif/core into my project
Describe the bug Hi! We (shopify CLI) have a monorepo with our CLI and multiple plugins, and @oclif/core is a dependency on all of them.
We are trying to bundle each package with its dependencies, but when including @oclif/core in the bundle we can’t make it work: Running any command will crash on line 34 of command.ts
const pjson = requireJson<PJSON>(__dirname, '..', 'package.json')
I assume is looking for the @oclif/core package.json, but since the dependency is being bundled there isn’t one.
Is there a way to avoid this? I see that this pjson is only used for a debug log, can we ignore the error if the file doesn’t exist instead of crashing? I can make the PR if you agree with this approach 😃
Thanks!
To Reproduce
Having a CLI, bundle it with esbuild, running any command should trigger this.
Expected behavior Everything should work normally.
About this issue
- Original URL
- State: closed
- Created 4 months ago
- Comments: 15 (6 by maintainers)
This is an example CLI where we are bundling with esbuild: https://github.com/isaacroldan/oclif-cli-bundled. This project includes the
@oclif/plugin-commands.After cloning you can notice the
distfolder already contains the output, and there is nonode_modules.Without running
npm i, run:It will work, because
@oclif/coreis bundled. But it is complaining that it can’t find thecommandsplugin. An of course./bin/run.js commandsdoesn’t workIf you then run
npm install, it will create thenode_modulesfolder and./bin/run.js commandswill work, becauseoclifcan find it in the node_modules folder.So things happening here:
distfolder that there is no reference to it)package.jsonfor the plugin, which will be imposible because will never have a node_modules folder.Notes:
npm run build, that runs the script inbin/bundle.jsLet me know what you think 😃
Yep, is a bit late on my timezone but I’ll prepare and share something tomorrow 😃