babel-plugin-lodash icon indicating copy to clipboard operation
babel-plugin-lodash copied to clipboard

Breaks when using "cwd" and "id" config options

Open danny-andrews opened this issue 7 years ago • 1 comments

This plugin gives TypeError: src/components/PasswordReset/PasswordReset.jsx: Cannot read property 'forEach' of undefined when using cwd and id. Example:

{
  "plugins": [["lodash", { "id": ["material-ui", "redux-form-material-ui"], "cwd": "./deep/dir" }]]
}

After doing some digging, it appears this commit caused the regression.

This is because the first time we call config is here (where cwd defaults to process.cwd()). The second time is here where cwd is whatever you set it in .baberc, so we purge module cache. However, the old ids are still there and we try to loop over them here.

I'd be happy to make a PR once it's verified this is a bug, and that the offending commit can't just be reverted as a fix.

danny-andrews avatar Aug 08 '17 22:08 danny-andrews

p.s. You can reproduce this error by changing:

'plugins': [[plugin, { 'id': lodashId }]]`

to

'plugins': [[plugin, { 'id': lodashId, 'cwd': './' }]]

here

danny-andrews avatar Aug 08 '17 22:08 danny-andrews