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.

Lerna v4 uses named imports

See original GitHub issue

After upgrading my project to use Lerna v4.0.0, I can no longer run commitlint.

Expected Behavior

Commit checks should run as usual when using Lerna v4.0.0

Current Behavior

Commitlint blows up when running the commit hooks. The following error occurs in @commitlint\config-lerna-scopes\index.js:47:20 - “TypeError: Project is not a constructor”.

Affected packages

  • config-lerna-scopes

Possible Solution

Add another check for lerna version in the getPackages function:

const lernaVersion = getLernaVersion(cwd);
if (semver.lt(lernaVersion, '3.0.0')) {
	const Repository = importFrom(cwd, 'lerna/lib/Repository');
	const PackageUtilities = importFrom(cwd, 'lerna/lib/PackageUtilities');

	const repository = new Repository(cwd);
	return PackageUtilities.getPackages({
		packageConfigs: repository.packageConfigs,
		rootPath: cwd,
	});
}

// New check for less than v4.0.0
if (semver.lt(lernaVersion, '4.0.0')) {
	const Project = importFrom(cwd, '@lerna/project');
	const project = new Project(cwd);
	return project.getPackages();
}

const { getPackages } = importFrom(cwd, '@lerna/project');
return getPackages();

Steps to Reproduce (for bugs)

  1. First step - upgrade solution to use Lerna v4.0.0
  2. Second step - run pre-commit checks

Context

This issue prevents me from running pre-commit checks, so I can only commit code by skipping the checks with the --no-verify flag.

Your Environment

Executable Version
commitlint --version @commitlint/cli@12.0.0
git --version git version 2.29.2.windows.2
node --version v14.15.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
escapedcatcommented, Feb 16, 2021

Thanks, lerna v4 just came out and we haven’t added support yet.

1reaction
johngnappcommented, Mar 10, 2021

Works like a dream, great work everyone! 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Imports from a lerna shared package seem to require src at ...
I am new to Typescript, javascript, & lerna but this seems wrong to me. It seems like it should just be: import {GreatClass}...
Read more >
lerna/import - npm.io
This is useful for gathering pre-existing standalone packages into a Lerna repo. Each commit is modified to make changes relative to the package...
Read more >
@lerna/import | Yarn - Package Manager
Import a package into the monorepo with commit history. lerna, command ... Usage. $ lerna import <path-to-external-repository>.
Read more >
Setting up a monorepo with Lerna for a TypeScript project
lerna bootstrap installs and links all dependencies, both local and remote. When using lerna add , the lerna bootstrap command is called ......
Read more >
Configuring TypeScript for multiple packages in a Lerna + ...
The aim of this article will be so you can import TypeScript code from one ... For me I called mine tsconfig.api-base.json as...
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