Skip to content

Cannot find module 'conventional-changelog-conventionalcommits' when using parserPreset #847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 4 tasks
CrispyDrone opened this issue Nov 2, 2019 · 8 comments
Closed
1 of 4 tasks

Comments

@CrispyDrone
Copy link

When I try to add parserPreset to my commitlint.config.js, I receive the following error:

C:\Program Files\nodejs\node_modules\@commitlint\cli\lib\cli.js:119
        throw err;
        ^
Error: Cannot find module 'conventional-changelog-conventionalcommits'
    at Function.Module._resolveFilename (module.js:538:15)
    at resolveFileName (C:\Program Files\nodejs\node_modules\@commitlint\cli\node_modules\resolve-from\index.js:29:39)
    at resolveFrom (C:\Program Files\nodejs\node_modules\@commitlint\cli\node_modules\resolve-from\index.js:43:9)
    at module.exports (C:\Program Files\nodejs\node_modules\@commitlint\cli\node_modules\resolve-from\index.js:46:47)
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\@commitlint\cli\node_modules\@commitlint\load\lib\index.js:54:54)
    at <anonymous>

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Steps to Reproduce (for bugs)

  1. Install @commitlint/cli, @commitlint/config-conventional (and optionally my plugin commitlint-plugin-cleanfeet)
  2. Ensure parserPreset: 'conventional-changelog-conventionalcommits', is present in commitlint.config.js
  3. Execute echo 'chore: Stuff' | commitlint
commitlint.config.js
module.exports = {
	parserPreset: 'conventional-changelog-conventionalcommits',
	extends: ['@commitlint/config-conventional'],
	plugins: ['cleanfeet'],
	rules: {
		'footer-format': [
			2, 
			'always', 
			[
				'^BREAKING CHANGE: .*',
				'^[a-zA-Z0-9-]+: .*',
				'^[a-zA-Z0-9-]+ #.*'
			]
		],
		'footer-max-occurrence-breaking-change': [2, 'always', { max: 1, regex: /^BREAKING CHANGE: .*$/ }]
	}
};

Your Environment

Executable Version
commitlint --version 8.2.0
git --version 2.16.1.windows.4
node --version v8.9.4
@byCedric
Copy link
Member

byCedric commented Nov 3, 2019

Could you try this version to see if the problem still persists? npm install --save commitlint@next

@CrispyDrone
Copy link
Author

Hi,

Thank you for your response.

Something that I forgot to mention is that I had installed commitlint as follows:

npm install -g @commitlint/cli @commitlint/config-conventional commitlint-changelog-conventionalcommits

Right now I first did an uninstall of these global packages and cleaned my entire local node_modules folder.

Then I executed:

npm install --save commitlint@next @commitlint/cli@next commitlint-plugin-cleanfeet conventional-changelog-conventionalcommits

And now it is working.

Thank you for your help.

@CrispyDrone
Copy link
Author

However it seems that when I install the exact same packages, but globally, I receive an error:
(Everything is working locally now, when I use npx commitlint)

C:\Program Files\nodejs\node_modules\commitlint\cli.js:8
const bin = path.join(pkgDir, manifest.bin.commitlint);
                                                                   ^

TypeError: Cannot read property 'commitlint' of undefined
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\commitlint\cli.js:8:44)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

Is this not possible? I'm trying to set up a workflow at work using a git hook which will call commitlint, but I'd prefer not having to install all these packages in every repository.

@byCedric
Copy link
Member

byCedric commented Nov 4, 2019

I think your NPM might be a bit confused because of commitlint and @commitlint/cli. commitlint is just an alias package that calls @commitlint/cli. Could you try installing @commitlint/cli@next without commitlint@next?

@CrispyDrone
Copy link
Author

Yes you were right. Thank you very much for your help.

@CrispyDrone
Copy link
Author

Hello again,

For some reason I can't get this work any more. I'm not sure if it ever worked in the first place to be honest, I might have actually been testing it in a repository where I had local packages installed.

I've been revisiting this today and I added a simple console.log statement to the C:\Program Files\nodejs\node_modules\@commitlint\cli\node_modules\@commitlint\load\lib\index.js and apparently the variable base is set to the local directory of where I'm invoking commitlint from instead of the directory where commitlint is installed.

When I install this as a global package I would expect it to be able to resolve conventional-changelog-conventionalcommits in the global package directory instead of it trying to search it in the local directory where I'm invoking commitlint from. Otherwise I still need to install these packages locally which is what I'm trying to avoid in the first place.

image
image

@CrispyDrone
Copy link
Author

CrispyDrone commented Apr 27, 2020

I tried to use resolveGlobal in case the resolveFrom fails, but on my machine this searches in a folder located in AppData even though my global packages are installed in my nodejs folder under program files.

Do you think this could be considered a bug in the global-dirs package? I'll try to check my work pc again to see what the npm prefix path is on it (see this https://stackoverflow.com/a/43398997 ), but I would have expected global-dirs to make use of that somehow.

For the moment I've decided to just install everything locally in every single repository I want to use commitlint in.

@escapedcat
Copy link
Member

Closing this. This seems to be a duplicate of mentioned #613. We do not need serveral issues about the issue with global installs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants