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.

Version 5.2.0+ -- TypeError: Cannot read property 'reduce' of undefined

See original GitHub issue

When upgrading gluegun from Cosmiconfig 5.1.0 to 5.2.0, I’m getting an error in my tests:

  ● runs a command explicitly

    TypeError: Cannot read property 'reduce' of undefined

      at getPropertyByPath (node_modules/cosmiconfig/dist/getPropertyByPath.js:15:21)
      at Explorer.loadPackageProp (node_modules/cosmiconfig/dist/createExplorer.js:177:30)
      at Explorer.loadFileContent (node_modules/cosmiconfig/dist/createExplorer.js:230:12)
      at Explorer.createCosmiconfigResultSync (node_modules/cosmiconfig/dist/createExplorer.js:263:31)
      at Explorer.loadSearchPlaceSync (node_modules/cosmiconfig/dist/createExplorer.js:158:17)
      at Explorer.searchDirectorySync (node_modules/cosmiconfig/dist/createExplorer.js:136:21)
      at run (node_modules/cosmiconfig/dist/createExplorer.js:108:27)
      at cacheWrapper (node_modules/cosmiconfig/dist/cacheWrapper.js:14:18)
      at Explorer.searchFromDirectorySync (node_modules/cosmiconfig/dist/createExplorer.js:117:14)
      at Explorer.searchSync (node_modules/cosmiconfig/dist/createExplorer.js:102:17)

  ● runs a command via passed in args

    TypeError: Cannot read property 'reduce' of undefined

      at getPropertyByPath (node_modules/cosmiconfig/dist/getPropertyByPath.js:15:21)
      at Explorer.loadPackageProp (node_modules/cosmiconfig/dist/createExplorer.js:177:30)
      at Explorer.loadFileContent (node_modules/cosmiconfig/dist/createExplorer.js:230:12)
      at Explorer.createCosmiconfigResultSync (node_modules/cosmiconfig/dist/createExplorer.js:263:31)
      at Explorer.loadSearchPlaceSync (node_modules/cosmiconfig/dist/createExplorer.js:158:17)
      at Explorer.searchDirectorySync (node_modules/cosmiconfig/dist/createExplorer.js:136:21)
      at run (node_modules/cosmiconfig/dist/createExplorer.js:108:27)
      at cacheWrapper (node_modules/cosmiconfig/dist/cacheWrapper.js:14:18)
      at Explorer.searchFromDirectorySync (node_modules/cosmiconfig/dist/createExplorer.js:117:14)
      at Explorer.searchSync (node_modules/cosmiconfig/dist/createExplorer.js:102:17)

There are no other changes – tests pass on 5.1.0 and fail with this error on 5.2.0.

Here’s the diff 5.1.0 to 5.2.0: https://github.com/davidtheclark/cosmiconfig/compare/71da3267ff24b3e80bd0e5fc955b4c45942c3548..f1750cde0b9c53bc577efa60d012a85a4dc4b823

If you’d like to experience it for yourself, do this:

git clone https://github.com/infinitered/gluegun.git
cd gluegun
git checkout deps/upgrade-several
yarn test # tests will pass
yarn add cosmiconfig@5.2.0
yarn test # tests will fail

This also happens on the latest cosmiconfig, 5.2.1.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
olsonpmcommented, Jun 4, 2019

No objections here. I just do think this is a value judgement because if we were talking about a larger product whose api has been stable for a long time, then I believe the bug fix similar to this one ought to be considered a breaking change because of the potential negative affect of changing it. In our case I think it’s fine though. If enough people run into issues because they depended on similar behavior, we can revert and add the check in a branch for v6.

I can submit a PR to Gluegun to add an if statement to prevent the tests from failing.

2reactions
davidtheclarkcommented, Jun 4, 2019

Thanks for digging in, @olsonpm. So this is one of those pesky cases where usage contrary to the publicly documented API (moduleName is documented as required) had an effect that somebody relied on, and that effect has changed.

I do think this fix should be introduced as a patch in order to make the behavior consistent with previous versions - I could also see wanting to add a check to make sure moduleName is a truthy string.

I would favor fixing the bug (unpredictable behavior when you don’t pass a required parameter) rather than codifying the bug as a feature. Since this fix would be perfectly compatible with the publicly documented API, a patch release is what semver expects (“Bug fixes not affecting the API increment the patch version”). (Yes, this might break somebody’s build if they’re relying on the undocumented buggy behavior, but that’s always a danger when fixing a bug.)

If we are going to add type assertions against the moduleName parameter, we may as well also add them against all the options, to prevent similar issues in the future.

Any objections to that proposal: fixing this with parameter type assertions, and releasing that as a patch?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'reduce' of undefined
every time i run my app. It says the error is in my selector file which is the one below and specifacally in...
Read more >
Cannot read property 'reduce' of undefined #38 - GitHub
I just installed npm-audit-resolver as described and executed resolve-audit and immediately got this error message: >>>> npm audit --json ...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
cannot read properties of undefined (reading 'consumer')
Your issue is that your .find() method is returning undefined , so you can't access properties on product such as .name as it...
Read more >
Js-error "TypeError: Cannot read property 'reduce ... - YouTrack
Js-error "TypeError: Cannot read property 'reduce' of undefined" on code rewiews tab ; State, Verified V ; Released in build, 6.5 ; Assignee,...
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