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

Support xo.config.cjs and .xo-config.cjs #561

Merged
merged 1 commit into from Jun 21, 2021
Merged

Support xo.config.cjs and .xo-config.cjs #561

merged 1 commit into from Jun 21, 2021

Conversation

joelpurra
Copy link
Contributor

@joelpurra joelpurra commented Jun 15, 2021

  • Fixes ERR_REQUIRE_ESM error from cosmiconfig.
  • Enables using xo.config.cjs/.xo-config.cjs in ESM packages with "type": "module".

Fixes #468.

See

Sample error output; problem fixed by this commit.

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /my-code/.xo-config.js
require() of ES modules is not supported.
require() of /my-code/.xo-config.js from /my-code/node_modules/cosmiconfig/dist/loaders.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename .xo-config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /my-code/package.json.

It's a start, but I don't think this fix is a golden bullet for ESM modules depending on xo. It fixes small-ish test cases without issue, but mixing ESM/non-ESM code may very well lead to further issues.

@sindresorhus
Copy link
Member

You need to update https://github.com/xojs/xo#config

@sindresorhus sindresorhus changed the title Support xo.config.cjs, .xo-config.cjs Support xo.config.cjs and .xo-config.cjs Jun 20, 2021
- Fixes `ERR_REQUIRE_ESM` error from `cosmiconfig`.
- Enables using `xo.config.cjs`/`.xo-config.cjs` in ESM packages with `"type": "module"`.

Fixes #468.

See

- #468
- https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

Sample error output; problem fixed by this commit.

```text
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /my-code/.xo-config.js
require() of ES modules is not supported.
require() of /my-code/.xo-config.js from /my-code/node_modules/cosmiconfig/dist/loaders.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename .xo-config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /my-code/package.json.
```
@joelpurra
Copy link
Contributor Author

joelpurra commented Jun 21, 2021

@sindresorhus: yup. Now added/mentioned the .cjs config files.

@sindresorhus sindresorhus merged commit 374dd73 into xojs:main Jun 21, 2021
@sindresorhus
Copy link
Member

Thanks :)

@joelpurra joelpurra deleted the xo-config-cjs branch June 21, 2021 09:33
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

Successfully merging this pull request may close these issues.

Node 14 ES Module: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: xo.config.js
2 participants