commitlint: TypeError: format is not a function
Expected Behavior
I’m trying to commit in a new repository that uses husky and my commit should work and pass husky checks as expected.
Current Behavior
When I try to commit, I see the following:
husky > commit-msg (node v10.3.0)
/Users/mprzybylski/Work/Livongo/fe-utils/node_modules/@commitlint/cli/lib/cli.js:113
throw err;
^
TypeError: format is not a function
at /Users/mprzybylski/Work/Livongo/fe-utils/node_modules/@commitlint/cli/lib/cli.js:193:18
at run (/Users/mprzybylski/Work/Livongo/fe-utils/node_modules/babel-polyfill/node_modules/core-js/modules/es6.promise.js:75:22)
at /Users/mprzybylski/Work/Livongo/fe-utils/node_modules/babel-polyfill/node_modules/core-js/modules/es6.promise.js:92:30
at flush (/Users/mprzybylski/Work/Livongo/fe-utils/node_modules/babel-polyfill/node_modules/core-js/modules/_microtask.js:18:9)
at process._tickCallback (internal/process/next_tick.js:61:11)
husky > commit-msg hook failed (add --no-verify to bypass)
Affected packages
- cli
- core
- prompt
- config-angular
Possible Solution
I’m not sure, and the odd thing is this works in my pre-existing repos, but it fails in this new one.
Steps to Reproduce (for bugs)
- Make changes to files.
- Commit changes. Error.
I’ve created a small repo that reproduces the problem here: https://github.com/reintroducing/commit-test
commitlint.config.js
```js module.exports = { extends: ['@spothero/commitlint-config'] }; ```Context
I can’t commit to the new repo unless i bypass husky checks. I’m using a custom commitlint config which can be found here: https://github.com/spothero/commitlint-config
Your Environment
Executable | Version |
---|---|
commitlint --version |
7.5.2 |
git --version |
2.20.1 (Apple Git-117) |
node --version |
10.3.0 |
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 3
- Comments: 36 (10 by maintainers)
Commits related to this issue
- fix: ensure format() is available as commonjs default export #645 — committed to conventional-changelog by marionebl 5 years ago
- fix: fix @commitlint/core imports The commitlint core doesn't correctly export the default exports from its constituent dependencies. ref conventional-changelog/commitlint#645 — committed to mixmaxhq/semantic-commitlint by deleted user 5 years ago
- chore(release): 1.0.2 [skip ci] ### [1.0.2](https://github.com/mixmaxhq/semantic-commitlint/compare/v1.0.1...v1.0.2) (2019-11-20) ### Bug Fixes * explicitly depend on the conventionalcommits config... — committed to mixmaxhq/semantic-commitlint by semantic-release-bot 5 years ago
- Rename CHANGELOG.md to Ishmaello/CHANGELOG.md # Change Log All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for com... — committed to Ishmaello by Ishmaello a year ago
- fix: commitlint install hoist Relates-To: conventional-changelog/commitlint#645 Signed-off-by: Sam Gammon <sam@elide.ventures> — committed to elide-dev/elide by sgammon 2 months ago
- fix: commitlint install hoist Relates-To: conventional-changelog/commitlint#645 Signed-off-by: Sam Gammon <sam@elide.ventures> — committed to elide-dev/elide by sgammon 2 months ago
- fix: commitlint install hoist Relates-To: conventional-changelog/commitlint#645 Signed-off-by: Sam Gammon <sam@elide.ventures> — committed to elide-dev/elide by sgammon 2 months ago
- fix: commitlint install hoist Relates-To: conventional-changelog/commitlint#645 Signed-off-by: Sam Gammon <sam@elide.ventures> — committed to elide-dev/elide by sgammon 2 months ago
@robweiss22 @JounQin reinstalling
node_modules
did it for me. I tried with many different commits, with different options, but after deletingnode_modules
and installing them again (@commitlint/cli
v19.0.3), everything worked ok, and I wasn’t able to reproduce the issue. For what it’s worth, this error happened to me only when using pnpm instead of npm.removing node_module with pnpm did help
Hi! Got this error on 19.0.3 (Node 21.2.0). It’s on
@commitlint/cli
:I’m importing from
@commitlint/format
and I have the same problem.The docs for @commitlint/format are no longer correct.
Test code for
@commitlint/format
:Result: 7.5.0
Result: 7.6.0
Test code for
@commitlint/core
:Result: 7.5.0
Result: 7.6.0
To me this is actually a breaking change for
@commitlint/format
and@commitlint/core
since the API has changed in a non-backwards compatible way.Is this intentional and going forward we should import from
require('@commitlint/format').default
?I ran into this today, and adding:
… to
.npmrc
, then runningpnpm install
, fixed it for me, withpnpm@9.0.5
.give it a push, I’m getting this in 19.0.3
this is unrelated, as babel is not used to compile code anymore
in theory yes, but this is really bad idea, as code is going to be way slower (due to transforms)
personally i will recommend adding non default export to load like it has been done to format, and let ppl import as
@elliotleelewis thanks for the info.
Someone just mentioned that the babel preset ist still targeting node v6.
Might be good to clean this up. Instead of targeting
es5
maybe we should just targetnode 12
because that’s the currently supported node version.I think the problem is with your
tsconfig.shared.json
. Your target is set toes2017
instead ofes5
, so the default method being exported is an async method, and I’m not sure if therequire(...)
syntax stumbles over that?Any particular reason why we’re targeting
es2017
vses5
?EDIT: Here’s what I see when inspecting a couple of packages’ contents…
@commitlint/resolve-extends
works perfectly fine, and here is its default export (lines 23 and 35):@commitlint/lint
doesn’t work, and here is its default export (lines 12 and 117):The only difference that I can see between them is the
async
tag on the method declaration in@commitlint/lint
? Usingtarget: "es5"
should fix that? 😃Yep, 9.1.1
@commitlint/lint
and@commitlint/load
are broken.The fix is just add
.default
:const load = require('@commitlint/load').default
. The API docs need to be updated if this was intended.This is also broken in
9.1.1
with@commitlint/lint
. 😢Get the same error:
TypeError: lint is not a function
Hi @marionebl
This is broken again in 8.0.0 with no mention in the changelog.
The imports for
read
,load
,lint
all have the default export exposed. Is the plan to change those as well?Either way, I didn’t see the breaking change for
format
in the changelog so I am unsure if this is intentional.This change solves it, but is is inconsistent with the sibling packages:
Fixed via
@commitlint/format@7.6.1