Add support to `.cjs` (common) and `.mjs` (module) config file
See original GitHub issueExpected Behavior
If config file is commitlint.config.mjs
or commitlint.config.cjs
is expected that works
Current Behavior
Is ignored
Affected packages
- load
Possible Solution
in commitlint/@commitlint/load/src/utils/load-config.ts
at loadConfig:
// ...
const moduleName = 'commitlint';
const explorer = cosmiconfig(moduleName, {
searchPlaces: [
'package.json',
`.${moduleName}rc`,
`.${moduleName}rc.json`,
`.${moduleName}rc.yaml`,
`.${moduleName}rc.yml`,
`.${moduleName}rc.ts`,
`.${moduleName}rc.js`,
`${moduleName}.config.ts`,
`${moduleName}.config.js`,
// add it here
`${moduleName}.config.cjs`,
`${moduleName}.config.mjs`,
],
loaders: {
'.ts': TypeScriptLoader,
},
};
// ...
```
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:11 (5 by maintainers)
Top Results From Across the Web
support `mjs` extensions out of box · Issue #224 - GitHub
I would prefer this work doesn't block the release of v7.0 (as type: "module" will still be unblocked via .cjs configuration files), and...
Read more >How to Create a Hybrid NPM Module for ESM and CommonJS.
Creating a single NPM module that works in all environments.
Read more >Support ESM in next.config.js - Stack Overflow
1 Answer 1 · 3. having next.config.mjs and type: 'module' in package.json results in error: require() of ES Module /usr/app/.next/server/pages/_ ...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
Node.js supports two extensions to help with this: .mjs and .cjs . .mjs files are always ES modules, and .cjs files are always...
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
CJS is the default; you have to opt-in to ESM mode. You can opt-in to ESM mode by renaming your script from .js...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
v13.2.0 was technically a breaking change — in v13.1.0 (before #2698),
commitlint.config.cjs
worked as a config file without having to specify-g commitlint.config.cjs
. Like @k2snowman69, I had to debug and look at the code to discover thatcommitlint.config.cjs
is no longer being searched for.It was quite confusing for me who just ran
pnpm recursive upgrade
and got this:It was my mistake. In the pr at the time we discussed about the support of cjs.
My opinion is that cosmiconfig currently does not support esm. The distinction between
cjs
andmjs
will only be necessary in the future whenmjs
is supported by default.However, in fact when
"type": "module"
is declared inpackage.json
, it is necessary to usecjs
in order to supportmodule.export
syntax, and there is also a default configuration forcjs
before, which will cause potential breaking changes if modified.In case this happens in the future, for example, cosmiconfig supports
mjs
but now the searchplace overwrites the default configuration, this should merge.ts
or other formats to the default, but now cosmiconfig does not export the default searchplace. So it may be difficult to sync.