Skip to content
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

TypeError: Cannot read property 'length' of undefined #53

Closed
alexander-akait opened this issue Aug 21, 2017 · 3 comments
Closed

TypeError: Cannot read property 'length' of undefined #53

alexander-akait opened this issue Aug 21, 2017 · 3 comments
Assignees
Labels
bug 🪲 Something isn't working

Comments

@alexander-akait
Copy link
Contributor

alexander-akait commented Aug 21, 2017

  • A little info about your environment
    • npm-package-json-lint version 2.8.0
    • npm version 5.3.0
    • node version 8.4.0
  • The output from npm-package-json-lint
TypeError: Cannot read property 'length' of undefined
/path/to/node_modules/npm-package-json-lint/src/cli.js:28
  throw new Error(err);
  ^

Error: TypeError: Cannot read property 'length' of undefined
    at handleError (/path/to/node_modules/npm-package-json-lint/src/cli.js:28:9)
    at Object.<anonymous> (/path/to/node_modules/npm-package-json-lint/src/cli.js:126:3)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3
  • What you expected to happen
    Not throw error.
  • The steps to reproduce the problem
  1. Create npmpackagejsonlint.config.js with prefer-property-order rule.
module.exports = {
  rules: {
    "prefer-property-order": ["error", [
      "name",
      "version",
      "description",
      "keywords",
      "homepage",
      "bugs",
      "license",
      "author",
      "contributors",
      "files",
      "main",
      "jsnext:main",
      "bin",
      "man",
      "directories",
      "repository",
      "scripts",
      "config",
      "dependencies",
      "devDependencies",
      "peerDependencies",
      "bundleDependencies",
      "bundledDependencies",
      "optionalDependencies",
      "engines",
      "engineStrict",
      "os",
      "cpu",
      "preferGlobal",
      "private",
      "publishConfig"
    ]]
  }
};
  1. Create package.json.
{
  "name": "test",
  "version": "0.0.4",
  "description": "test"
}
tclindner pushed a commit that referenced this issue Aug 22, 2017
Add defaults if an empty array is passed. Prevent the rule from failing
if package.json file is missing a node that exists in the preferred
property list.
@tclindner tclindner self-assigned this Aug 22, 2017
@tclindner tclindner added the bug 🪲 Something isn't working label Aug 22, 2017
@tclindner
Copy link
Owner

Thank you for catching this, @evilebottnawi! I've release v2.8.1. It should address your issue. It also contains feedback from #50. Let me know what you think.

@alexander-akait
Copy link
Contributor Author

@tclindner problem still exists 😞 use post above to reproducible error.
In function(packageJsonData, lintType, preferredOrder) preferredOrder contains undefined, but lintType containts

[ 'error',
  [ 'name',
    'version',
    'description',
    'keywords',
    'homepage',
    'bugs',
    'license',
    'author',
    'contributors',
    'files',
    'main',
    'jsnext:main',
    'bin',
    'man',
    'directories',
    'repository',
    'scripts',
    'config',
    'dependencies',
    'devDependencies',
    'peerDependencies',
    'bundleDependencies',
    'bundledDependencies',
    'optionalDependencies',
    'engines',
    'engineStrict',
    'os',
    'cpu',
    'preferGlobal',
    'private',
    'publishConfig' ] ]

@tclindner
Copy link
Owner

I'm so sorry about that @evilebottnawi! I believe I have identified the issue. The rules loader was not properly interpreting this rule as a "array" type rule. I've released v2.8.2 to address that. Can you please try it out and see if it resolves your issue? Sorry again about the issues with this rule.

P.S. I will be logging an enhancement to improve the rules loader to avoid hitting this issue in the future. I'll tag you on that ticket. Thank you again for helping improve this project 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants