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

No mutable exports error #660

Closed
NullDivision opened this issue Nov 10, 2016 · 9 comments · Fixed by renovatebot/renovate#217
Closed

No mutable exports error #660

NullDivision opened this issue Nov 10, 2016 · 9 comments · Fixed by renovatebot/renovate#217
Labels

Comments

@NullDivision
Copy link

I get the following error when running version 2.2.0:

Cannot read property 'kind' of null
TypeError: Cannot read property 'kind' of null
    at checkDeclaration (/home/nulldivision/Projects/node_modules/eslint-plugin-import/lib/rules/no-mutable-exports.js:10:24)
    at checkDeclarationsInScope (/home/nulldivision/Projects/node_modules/eslint-plugin-import/lib/rules/no-mutable-exports.js:24:15)
    at EventEmitter.handleExportNamed (/home/nulldivision/Projects/node_modules/eslint-plugin-import/lib/rules/no-mutable-exports.js:46:11)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (/home/nulldivision/Projects/node_modules/eslint/lib/util/node-event-generator.js:40:22)
    at CodePathAnalyzer.enterNode (/home/nulldivision/Projects/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at CommentEventGenerator.enterNode (/home/nulldivision/Projects/node_modules/eslint/lib/util/comment-event-generator.js:97:23)
    at Controller.enter (/home/nulldivision/Projects/node_modules/eslint/lib/eslint.js:927:36)
    at Controller.__execute (/home/nulldivision/Projects/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
@ljharb
Copy link
Member

ljharb commented Nov 10, 2016

Can you provide the code it's erroring out on?

@NullDivision
Copy link
Author

NullDivision commented Nov 10, 2016

Sadly I cannot. The codebase is fairly big and more importantly proprietary.

Based on the error I'm thinking if it wouldn't make sense to have handle
the case by checking if node has an actual value. I'm not sure what the
case might be where def might not have a parent (or what def actually
is).

@jfmengels
Copy link
Collaborator

It would be really helpful to have a MVP / example of the error. Even if your codebase is big and proprietary, you could do the following to help us fix this (while maintaining the privacy of your codebase):

  • Try to pinpoint the file(s) that cause the error: Run eslint on only some of the folders, and dive deeper into the folders where you keep having this crash.
  • Once you have the file, comment/remove some of the code until you are left with a short code example
  • Change the code in order to hide any sensible information (change variable names, remove most logic from the code, ...)

In the case of this rule, it's very likely that you'll end up with a very short code example which will not betray any sensitive information about your project :)

If you find the time to do this, that'd be awesome!

@benmosher
Copy link
Member

I'm pretty unfamiliar with EScope, but @NullDivision is right that def.parent is optional and thus is worth checking.

I goofed around with a few weird syntaxes (undeclared / unbound identifiers) and couldn't reproduce the error, but I suspect the change in bfdc2bb should resolve this.

Would still love a repro case, if you can manage it. 😅

@chrisnojima
Copy link

@benmosher Hi, I have a way to reproduce this w/ v2.2.0. In this commit I work around the issue. keybase/client@199bb2a If left as the commit before then it'll give the above error.

@rwe
Copy link

rwe commented Jan 10, 2017

@benmosher Is it possible to get a minor bump release for this? The referenced commit fixes it.

I believe it's caused by using the syntax-flow Babel plugin and exporting type definitions. For reference, here's an example of a failing node:

Definition {
  type: 'Variable',
  name:
   Node {
     type: 'Identifier',
     start: 17,
     end: 19,
     loc: SourceLocation { start: [Object], end: [Object], identifierName: 'ID' },
     name: 'ID',
     range: [ 17, 19 ],
     _babelType: 'Identifier',
     parent:
      Node {
        type: 'TypeAlias',
        start: 12,
        end: 29,
        loc: [Object],
        id: [Circular],
        typeParameters: null,
        right: [Object],
        leadingComments: [Object],
        range: [Object],
        _babelType: 'TypeAlias',
        parent: [Object] } },
  node:
   Node {
     type: 'TypeAlias',
     start: 12,
     end: 29,
     loc: SourceLocation { start: [Object], end: [Object] },
     id:
      Node {
        type: 'Identifier',
        start: 17,
        end: 19,
        loc: [Object],
        name: 'ID',
        range: [Object],
        _babelType: 'Identifier',
        parent: [Circular] },
     typeParameters: null,
     right:
      Node {
        type: 'StringTypeAnnotation',
        start: 22,
        end: 28,
        loc: [Object],
        range: [Object],
        _babelType: 'StringTypeAnnotation',
        parent: [Circular] },
     leadingComments: [ [Object] ],
     range: [ 12, 29 ],
     _babelType: 'TypeAlias',
     parent:
      Node {
        type: 'Program',
        start: 0,
        end: 983,
        loc: [Object],
        comments: [Object],
        tokens: [Object],
        range: [Object],
        sourceType: 'module',
        directives: undefined,
        body: [Object],
        parent: null } },
  parent: null,
  index: null,
  kind: null }
Cannot read property 'kind' of null
TypeError: Cannot read property 'kind' of null
    at checkDeclaration (node_modules/eslint-plugin-import/lib/rules/no-mutable-exports.js:10:24)
    at checkDeclarationsInScope (node_modules/eslint-plugin-import/lib/rules/no-mutable-exports.js:25:15)
    at EventEmitter.handleExportNamed (node_modules/eslint-plugin-import/lib/rules/no-mutable-exports.js:47:11)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (node_modules/eslint/lib/util/node-event-generator.js:39:22)
    at CodePathAnalyzer.enterNode (node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:607:23)
    at CommentEventGenerator.enterNode (node_modules/eslint/lib/util/comment-event-generator.js:97:23)
    at Controller.enter (node_modules/eslint/lib/eslint.js:928:36)
    at Controller.__execute (node_modules/estraverse/estraverse.js:397:31)

Caused by code similar to:

type Foo = {};
type Bar = {};

export type {
  Foo,
  Bar,
};

@nickydonna
Copy link

nickydonna commented Mar 23, 2017

I having this issue with a file I use for flow types

File:

//@flow
type Activity = { id: string, name: string };
type DescriptionType = { name: string, text: string, remarks: string[] };
type DescriptionsType = { en: DescriptionType, es: DescriptionType };
type RecurrentDate = { times: Date[] };

type EditableTour = {
    props: Object
}

export type {
  Activity,
  DescriptionType,
  DescriptionsType,
  RecurrentDate,
  EditableTour,
};

.eslintrc

{
  "parser": "babel-eslint",
  "extends": "airbnb",
  "globals": {
    "document": true,
    "window": true,
    "process": true,
    "API_URL": true,
    "React$Element": true,
    "SyntheticEvent": true,
    "SyntheticInputEvent": true,
    "FormData": true,
    "fetch": true,
    "File": true
  },
  "rules": {
    "import/extensions": 0,
    "import/no-extraneous-dependencies": 0,
    "import/no-unresolved": 0,
    "react/jsx-filename-extension": 0,
    "linebreak-style": 0,
    "react/no-did-mount-set-state": 0,
    "spaced-comment": 0,
    "camelcase": 0,
    "react/no-multi-comp": 0
  }
}

please help!

hazeledmands pushed a commit to hazeledmands/eslint-plugin-import that referenced this issue May 17, 2017
This tests the bug reported in issue import-js#758, which was actually already fixed in
PR import-js#660.
@hazeledmands
Copy link

I've got a PR (#835) that adds a test for this :)

hazeledmands pushed a commit to hazeledmands/eslint-plugin-import that referenced this issue May 17, 2017
benmosher pushed a commit that referenced this issue May 18, 2017
This tests the bug reported in issue #758, which was actually already fixed in
PR #660.
@benmosher
Copy link
Member

published!

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

Successfully merging a pull request may close this issue.

8 participants