mediumroast / mediumroast_js

Mediumroast for GitHub CLI and API/SDK
https://www.mediumroast.io/product.html
Apache License 2.0
1 stars 0 forks source link

mrcli fails setup with Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'json2csv' imported from /usr/local/lib/node_modules/mediumroast_js/src/cli/output.js #48

Closed jgoodie closed 11 months ago

jgoodie commented 11 months ago

Unable to run mrcli setup:

Error messages states: "Cannot find package 'json2csv'". Even after installing json2csv, the error persists.

Discovered on Ubuntu 22.04.3 LTS.

john@medici:~$ npm --version 10.2.4

john@medici:~$ node -v v21.4.0

john@medici:~$ mrcli setup node:internal/modules/esm/resolve:853 throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null); ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'json2csv' imported from /usr/local/lib/node_modules/mediumroast_js/src/cli/output.js at packageResolve (node:internal/modules/esm/resolve:853:9) at moduleResolve (node:internal/modules/esm/resolve:910:20) at defaultResolve (node:internal/modules/esm/resolve:1130:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12) at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25) at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38) at ModuleWrap. (node:internal/modules/esm/module_job:85:39) at link (node:internal/modules/esm/module_job:84:36) { code: 'ERR_MODULE_NOT_FOUND' }

Node.js v21.4.0

miha42-github commented 11 months ago

@jgoodie I haven't tested with node 21, but let me know the experience. I believe it is fixed now. The problem was that I had an old stale module running around and was not using the new module which has a new maintainer.

The fix was:

  1. Make sure the latest for PlainJs json2csv was installed. In the package.json file this means "@json2csv/plainjs": "^7.0.4".
  2. In src/cli/output.js ensure that the new module is imported import {Parser} from '@json2csv/plainjs' and the new way to call the parser method was performed. This means that we'd construct a new Parser object with const csvParser = new Parser() and then call csvParser.parse(objs).
  3. Publish the new version.

To check the fix please run: sudo npm i -g mediumroast_js

jgoodie commented 11 months ago

@miha42-github it looks good. I'll close this out.

miha42-github commented 11 months ago

This is closed, the problem was the new module for json2csv was included in the package just not imported and used. This was fixed.