Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code: 'ERR_REQUIRE_ESM' #545

Open
astralarya opened this issue Mar 16, 2024 · 3 comments
Open

code: 'ERR_REQUIRE_ESM' #545

astralarya opened this issue Mar 16, 2024 · 3 comments

Comments

@astralarya
Copy link

astralarya commented Mar 16, 2024

Version: "kanel": "^3.8.8",
node: v20.8.0

Attempting to run kanel. Config file below:

yarn run v1.22.19
$ kanel
/Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/cli-progress/lib/formatter.js:1
const _stringWidth = require('string-width');
                     ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/string-width/index.js from /Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/cli-progress/lib/formatter.js not supported.
Instead change the require of index.js in /Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/cli-progress/lib/formatter.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/cli-progress/lib/formatter.js:1:22)
    at Object.<anonymous> (/Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/cli-progress/lib/generic-bar.js:3:20)
    at Object.<anonymous> (/Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/cli-progress/lib/single-bar.js:1:21)
    at Object.<anonymous> (/Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/cli-progress/cli-progress.js:1:20)
    at Object.<anonymous> (/Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/kanel/build/cli/main.js:8:40)
    at Object.<anonymous> (/Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/kanel/build/cli/index.js:3:16)
    at Object.<anonymous> (/Users/marakim/Documents/code/github/astralarya/rrobin/web/next/node_modules/kanel/bin/kanel:4:1) {
  code: 'ERR_REQUIRE_ESM'

Content of .kanelrc.js:

/** @type {import('kanel').Config} */
module.exports = {
  connection: {
    host: process.env.PGHOST,
    user: process.env.PGUSER,
    password: process.env.PGPASSWORD,
    database: process.env.PGDATABASE,
  },

  preDeleteOutputFolder: true,
  outputPath: "./src/sql",
};
@astralarya
Copy link
Author

astralarya commented Mar 16, 2024

This looks like it could be related:
https://stackoverflow.com/questions/69081410/error-err-require-esm-require-of-es-module-not-supported

Maybe it would be fixed if you added:

"module": true,

to the package.json?

@kristiandupont
Copy link
Owner

Yeah, the issue is that Kanel is not (yet) ESM-ready. Sadly, it's not quite as easy as changing that one line, and making the change will affect everyone who is not setting "module": true in their package.json. I do intend to do something about this because I am facing issues with it myself, but I can't guarantee when.

If you want a hacky workaround, I know one friend who comments out the "module": true line in his package.json every time he runs Kanel and then undoes that afterwards. I know, not pretty, but it does work...

@kevlened
Copy link

kevlened commented Mar 30, 2024

I ran into this issue for a project that uses "type": "module".

My workaround was to rename .kanelrc.js to .kanelrc.cjs, then override the config import:

kanel --config .kanelrc.cjs

Edit: this isn't necessary, because kanel automatically recognizes .kanelrc.cjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants