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.

TypeError: format is not a function

See original GitHub issue

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)

  1. Make changes to files.
  2. 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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:23 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
varlcommented, May 9, 2019

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:

const format = require('@commitlint/format')
console.log('format', typeof format)
format({})

Result: 7.5.0

format function

Result: 7.6.0

format object
// { default: [Function: format],
//  formatResult: [Function: formatResult] }
[ERROR] TypeError: format is not a function

Test code for @commitlint/core:

const { read, load, lint, format } = require('@commitlint/core')

console.log('format', typeof format)
console.log('load', typeof load)
console.log('read', typeof read)
console.log('lint', typeof lint)

Result: 7.5.0

format function
load function
read function
lint function

Result: 7.6.0

format object
load function
read function
lint function
[ERROR] TypeError: format is not a function

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?

1reaction
armano2commented, Jan 21, 2021

@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 target node 12 because that’s the currently supported node version.

this is unrelated, as babel is not used to compile code anymore

The only difference that I can see between them is the async tag on the method declaration in @commitlint/lint? Using target: “es5” should fix that? 😃

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

const { load } = require('@commitlint/load')
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: format is not a function in date-fns - Stack Overflow
TypeError : format is not a function. I have tried import, require but they all give same error. var format = require('date-fns/format') ...
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >
TypeError _(...).format is not a function in raspberry pi 3b+
TypeError _(...).format is not a function ... This topic was automatically closed 10 days after the last reply. New replies are no longer...
Read more >
client-side validation method: (intermediate value).format is ...
... same formatting function outside of this onChange listener function. ... error TypeError: (intermediate value).format is not a function.
Read more >
TypeError: not all arguments converted during string formatting
In Python, a TypeError is encountered when you perform an operation or use a function on an object of the incorrect type. You...
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