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 'forEach' of null #717

Closed
brunolemos opened this issue Jan 11, 2017 · 22 comments · Fixed by #797
Closed

TypeError: Cannot read property 'forEach' of null #717

brunolemos opened this issue Jan 11, 2017 · 22 comments · Fixed by #797

Comments

@brunolemos
Copy link

brunolemos commented Jan 11, 2017

Cannot read property 'forEach' of null
TypeError: Cannot read property 'forEach' of null
    at dependencies.forEach.dep (/node_modules/eslint-plugin-import/lib/ExportMap.js:182:43)
    at Map.forEach (native)
    at ExportMap.forEach (/node_modules/eslint-plugin-import/lib/ExportMap.js:182:23)
    at EventEmitter.ExportAllDeclaration (/node_modules/eslint-plugin-import/lib/rules/export.js:62:23)
    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)

I'm using airbnb rules on WebStorm editor.
My .eslintrc is the following:

{
  "parser": "babel-eslint",
  "extends": "airbnb",
  "env": {
    "es6": true,
    "jest": true
  },
  "plugins": [
    "babel",
    "flowtype",
    "import",
    "react",
    "react-native"
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "sourceType": "module"
  },
  "settings": {
    "import/extensions": [".js", ".jsx", ".android.js", ".ios.js"]
  },
  "rules": {
    "react/jsx-filename-extension": ["off"],
    "react/prefer-stateless-function": ["error", {
      "ignorePureComponents": true
    }],
    "no-case-declarations": ["off"],
    "no-underscore-dangle": ["off"],
    "no-nested-ternary": ["off"],
    "arrow-parens": 0,
    "babel/arrow-parens": 1,
    "react-native/no-unused-styles": 2,
    "react-native/split-platform-components": 2,
    "react-native/no-inline-styles": 2,
    "react-native/no-color-literals": 2
  }
}
@brunolemos
Copy link
Author

Possibly related to #348 because I'm using export * from './file' kinda often, in a nested way, like:

fileA.js
export * from './fileB

fileB.js
export * from './fileC

fileC.js
export * from './fileD

@brunolemos
Copy link
Author

brunolemos commented Jan 16, 2017

Confirmed that this bug happens when using exports like in the comment above.
Can you help? cc @benmosher @jfmengels

Line of code: ExportMap.js#L154

@brunolemos
Copy link
Author

brunolemos commented Jan 16, 2017

Found more details. This was causing the issue:

fileB.js

export * from 'warna';

Replaced it by:

export const darken = warna.darken;
export const lighten  = warna.lighten;

and now the error is gone.

@benmosher
Copy link
Member

benmosher commented Jan 20, 2017

this same warna: https://www.npmjs.com/package/warna?

I suspect there's a bug with export * from '[commonjs module in node_modules]'

@benmosher benmosher added the bug label Jan 20, 2017
@benmosher benmosher added this to the patch milestone Jan 20, 2017
@brunolemos
Copy link
Author

Yes

@jamiter
Copy link

jamiter commented Apr 10, 2017

Run into this as well. Any workaround?

@brunolemos
Copy link
Author

@jamiter check your export * from, at least one of them are causing the problem, probably if the package is written in es5 not es6. Workaround is to not use export *

benmosher added a commit that referenced this issue Apr 10, 2017
ignore deep CJS imports/exports
@cgarnier
Copy link

What is the workarround ?

@benmosher
Copy link
Member

@cgarnier the problem is with deep imports that terminate in a commonjs module reference. really I just need to test #797 though

@ljharb
Copy link
Member

ljharb commented Apr 24, 2017

@cgarnier #717 (comment)

Workaround is to not use export *

benmosher added a commit that referenced this issue May 18, 2017
ignore deep CJS imports/exports
@benmosher benmosher reopened this May 18, 2017
@benmosher
Copy link
Member

reopening to remember to create test

@leoplct
Copy link

leoplct commented Jun 16, 2018

Same problem if I use this (ember 3.1)

export default {
    name: 'zero',
    initialize: initialize
};

@ljharb
Copy link
Member

ljharb commented Jun 16, 2018

@leoplct can you file a separate issue for that?

@rjhilgefort
Copy link

Workaround is to not use export *

I can't really enumerate all the exports of the dependency I have. Rather, I could, but it would be pretty obnoxious because the dep is Ramda and it has probably 100 exports. Is there any other solution/work around?

@ljharb
Copy link
Member

ljharb commented Jul 25, 2018

@rjhilgefort is this still an issue with the latest version?

@rjhilgefort
Copy link

rjhilgefort commented Jul 25, 2018

I believe so. I just upgraded to 2.13.0 and I'm seeing the issue when I try to do export * from 'Ramda'. When I comment out that export, the eslint failure error is gone and I'm left with expected linter warns about the Ramda methods that aren't being exported.

TypeError: Cannot read property 'size' of null
    at dependencies.forEach.dep (/Users/rjhilgefort/Projects/charter/distillery-lint/node_modules/eslint-plugin-import/lib/ExportMap.js:71:51)
    at Set.forEach (<anonymous>)
    at ExportMap.get size [as size] (/Users/rjhilgefort/Projects/charter/distillery-lint/node_modules/eslint-plugin-import/lib/ExportMap.js:71:23)
    at processBodyStatement (/Users/rjhilgefort/Projects/charter/distillery-lint/node_modules/eslint-plugin-import/lib/rules/namespace.js:77:30)
    at Array.forEach (<anonymous>)
    at Program (/Users/rjhilgefort/Projects/charter/distillery-lint/node_modules/eslint-plugin-import/lib/rules/namespace.js:95:14)
    at listeners.(anonymous function).forEach.listener (/Users/rjhilgefort/Projects/charter/distillery-lint/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/rjhilgefort/Projects/charter/distillery-lint/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (/Users/rjhilgefort/Projects/charter/distillery-lint/node_modules/eslint/lib/util/node-event-generator.js:251:26)

Though, Ramda doesn't have a size method... so that's a bit perplexing...

@ljharb
Copy link
Member

ljharb commented Jul 25, 2018

the internal Map in ExportMap does, however. Thanks, that's helpful.

ljharb added a commit to ljharb/eslint-plugin-import that referenced this issue Aug 10, 2018
@ljharb
Copy link
Member

ljharb commented Aug 10, 2018

@rjhilgefort i think your issue will be fixed in the next release.

Leaving this open so a test can be added.

@rjhilgefort
Copy link

Awesome, thanks for the update and the work on this project!

@ljharb ljharb closed this as completed Feb 18, 2020
@Duarte206

This comment has been minimized.

@Duarte206

This comment has been minimized.

@ljharb

This comment has been minimized.

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

Successfully merging a pull request may close this issue.

8 participants