question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support to `.cjs` (common) and `.mjs` (module) config file

See original GitHub issue

Expected 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
cherryblossom000commented, Sep 30, 2021

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 that commitlint.config.cjs is no longer being searched for.

It was quite confusing for me who just ran pnpm recursive upgrade and got this:

⧗   input: chore: upgrade deps
✖   Please add rules to your `commitlint.config.js`
    - Getting started guide: https://git.io/fhHij
    - Example config: https://git.io/fhHip [empty-rules]

✖   found 1 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
2reactions
songhn233commented, Sep 30, 2021

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 that commitlint.config.cjs is no longer being searched for.

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 and mjs will only be necessary in the future when mjs is supported by default.

However, in fact when "type": "module" is declared in package.json, it is necessary to use cjs in order to support module.export syntax, and there is also a default configuration for cjs 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found