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.

Can't run commitlint on project with tsconfig.json

See original GitHub issue

When running commitlint on a typeScript project, I have an error because commitlint use the project tsconfig.json.

Expected Behavior

commitlint should not use the project typeScript configuration.

Current Behavior

commitlint produce the following traceback:

/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:843
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
error TS6053: File '@loopback/build/config/tsconfig.common.json' not found.

    at createTSError (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:843:12)
    at reportTSError (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:847:19)
    at createFromPreloadedConfig (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:858:36)
    at create (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:613:10)
    at register (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:580:15)
    at TypeScriptLoader (/usr/local/lib/node_modules/commitlint/node_modules/cosmiconfig-typescript-loader/dist/loader.js:7:51)
    at loadConfig (/usr/local/lib/node_modules/commitlint/node_modules/@commitlint/load/src/utils/load-config.ts:35:27)
    at load (/usr/local/lib/node_modules/commitlint/node_modules/@commitlint/load/src/load.ts:25:33)
    at main (/usr/local/lib/node_modules/commitlint/node_modules/@commitlint/cli/src/cli.ts:199:27)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  diagnosticCodes: [ 6053 ]
}

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

Steps to Reproduce (for bugs)

  1. clone the repository https://gitlab.mim-libre.fr/alphabet/laboite-blog-api.git
  2. execute commitlint --from HEAD~2 --to HEAD
commitlint.config.js
module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'body-max-line-length': [2, 'always', 120],
    'footer-max-line-length': [2, 'always', 120],
    'header-max-length': [2, 'always', 72],
  },
};

Context

We upgraded our commitlint container for our CI and now all typeScript project are failling.

Your Environment

Executable Version
commitlint --version 16.3.0
git --version 2.36.1
node --version 18.4.0

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

1reaction
baby-gnucommented, Jun 27, 2022

It looks like yes, I’m not sure it’s a good idea for commitlint to load the project configuration but I don’t know how to prevent that.

I managed to work around this issue by cd /tmp and execute commitlint --cwd /my/sources

1reaction
baby-gnucommented, Jun 27, 2022

Pity, looks like it’s somehow picking this up?: https://gitlab.mim-libre.fr/alphabet/laboite-blog-api/-/blob/dev/tsconfig.json#L3 Never had an issue with other projects using tsconfig.

It looks like yes, I’m not sure it’s a good idea for commitlint to load the project configuration but I don’t know how to prevent that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@threads/tsconfig - npm
Start using @threads/tsconfig in your project by running `npm i ... and add the following tsconfig.json in your project's root directory:.
Read more >
Run a TypeScript type check in your pre-commit hook using ...
A great way to prevent TypeScript compilation errors from bringing down your CI pipelines is to introduce a type check before you commit ......
Read more >
Error: TSError: Unable to compile TypeScript - Stack Overflow
I had met same issue. First I remove ts-node and typescript from package.json . then, npm install ts-node --save-dev npm install typescript ......
Read more >
Setup pre-commit hooks with husky v6 + commitlint + lint-staged
json and write the following script pre-commit which runs the lint-staged in our project. package.json. "scripts": { ... "pre-commit" ...
Read more >
Commitlint: Write more organized code - LogRocket Blog
Setting up Git hooks with commitlint. For commit message validations to run automatically on every Git commit command, we will use Husky, a...
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