code-narrator icon indicating copy to clipboard operation
code-narrator copied to clipboard

Cannot Use with an ESM project

Open NickPadilla opened this issue 2 years ago • 0 comments

I was playing around with this project, see if could get some docs built out for some open source. However, I could not get it to run as I am getting this error:

npx code-narrator
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/box/structures/structures-js/structures-api/code-narrator.config.js from /Users/box/.npm/_npx/e378fa2a901701d1/node_modules/code-narrator/dist/src/utils/CliHelper.js not supported.
Instead change the require of code-narrator.config.js in /Users/box/.npm/_npx/e378fa2a901701d1/node_modules/code-narrator/dist/src/utils/CliHelper.js to a dynamic import() which is available in all CommonJS modules.
    at /Users/box/.npm/_npx/e378fa2a901701d1/node_modules/code-narrator/dist/src/utils/CliHelper.js:73:96
    at async CliHelper.getConfig (/Users/box/.npm/_npx/e378fa2a901701d1/node_modules/code-narrator/dist/src/utils/CliHelper.js:73:30)
    at async /Users/box/.npm/_npx/e378fa2a901701d1/node_modules/code-narrator/dist/src/cli.js:12:22 {
  code: 'ERR_REQUIRE_ESM'
}

This is the folder within the open source I am trying to test this against. https://github.com/Kinotic-Foundation/structures/tree/main/structures-js/structures-api

I did need to modify the code-narrator.config.js to use import statements and not use require to get past the first error.

I believe using vite might be a better build tool, as it should allow building for both CommonJS and ESM. If I find the time, I might play around with this and see if can get it to work.. just don't have the time right now.

NickPadilla avatar Aug 25 '24 17:08 NickPadilla