frinyvonnick / gitmoji-changelog

A changelog generator for gitmoji 😜
https://www.npmjs.com/package/gitmoji-changelog
MIT License
390 stars 49 forks source link

Error: Cannot retrieve configuration for preset node. #205

Closed MarkLyck closed 3 years ago

MarkLyck commented 3 years ago

in an existing yarn/npm repository, with a valid package.json the yarn gitmoji-changelog or yarn gitmoji-changelog --init does not work for me.

I get the following error:

$ /Users/mark/ypm/colonynetworks/test-pwa/node_modules/.bin/gitmoji-changelog
▶  start     gitmoji-changelog v2.2.0
ℹ  info      init ./CHANGELOG.md
ℹ  info      No custom configuration found
ℹ  info      use preset node
✖  error     Error: Cannot retrieve configuration for preset node. 
    at main (/Users/mark/ypm/test-pwa/node_modules/gitmoji-changelog/src/cli.js:56:13)

I do not have a CHANGELOG.md already.

I have a package.json file with the version on line 3:

{
  "name": "test-pwa",
  "version": "0.1.4",
  "description": "testing PWAs",
  ...

since I just need the node preset, I did not setup a .gitmoji-changelogrc file

I installed it like so: yarn add -D gitmoji-changelog and running it with yarn.

I also tried running it with npx but same error.

I'm in a "normal" repo, not a monorepo and the package.json is at the root of my application, same place as I run the command.

Any idea why it can't retrieve the Configuration?

MarkLyck commented 3 years ago

@frinyvonnick I found the issue and opened a PR: https://github.com/frinyvonnick/gitmoji-changelog/pull/206

when const packageInfo = await readPkgUp()

is resolved in my repository I get this structure:

packageInfo {
  packageJson: {
    name: 'test-pwa',
    version: '0.1.4',
    description: 'testing PWAs',

the node preset expects to see:

packageInfo {
  pkg: { ... }

After some investigating I found that newer versions of https://github.com/sindresorhus/read-pkg-up changes the name from pkg to packageJson

Even though I have never manually installed read-pkg-up, I have the following in my yarn.lock file.

Likely. one of the newer versions are being used when I'm running gitmoji-changelog, and the new naming scheme is not found in the node preset.

read-pkg-up@^1.0.1:
  version "1.0.1"
  resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02"
  integrity sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=
  dependencies:
    find-up "^1.0.0"
    read-pkg "^1.0.0"

read-pkg-up@^2.0.0:
  version "2.0.0"
  resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz#6b72a8048984e0c41e79510fd5e9fa99b3b549be"
  integrity sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4=
  dependencies:
    find-up "^2.0.0"
    read-pkg "^2.0.0"

read-pkg-up@^3.0.0:
  version "3.0.0"
  resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-3.0.0.tgz#3ed496685dba0f8fe118d0691dc51f4a1ff96f07"
  integrity sha1-PtSWaF26D4/hGNBpHcUfSh/5bwc=
  dependencies:
    find-up "^2.0.0"
    read-pkg "^3.0.0"

read-pkg-up@^4.0.0:
  version "4.0.0"
  resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-4.0.0.tgz#1b221c6088ba7799601c808f91161c66e58f8978"
  integrity sha512-6etQSH7nJGsK0RbG/2TeDzZFa8shjQ1um+SwQQ5cwKy0dhSXdOncEhb1CPpvQG4h7FyOV6EB6YlV0yJvZQNAkA==
  dependencies:
    find-up "^3.0.0"
    read-pkg "^3.0.0"

read-pkg-up@^7.0.0, read-pkg-up@^7.0.1:
  version "7.0.1"
  resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-7.0.1.tgz#f3a6135758459733ae2b95638056e1854e7ef507"
  integrity sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==
  dependencies:
    find-up "^4.1.0"
    read-pkg "^5.2.0"
    type-fest "^0.8.1"

The PR I submitted, supports both cases without upgrading read-pkg-up.

Alternatively you can lock in the version to force an older compatible version of the package to run. Or upgrade the package and change the name to only support "packageJson"