lodash / babel-plugin-lodash

Modular Lodash builds without the hassle.
Other
1.96k stars 92 forks source link

TypeError: Cannot read property 'name' of undefined #188

Closed niftylettuce closed 6 years ago

niftylettuce commented 6 years ago

I believe this is related to #168.

Input:

src/config/utilities.js:

export hljs from 'highlight.js';
export _ from 'lodash';
export s from 'underscore.string';
export moment from 'moment';
export accounting from 'accounting';
export fa from 'font-awesome-assets';
export pluralize from 'pluralize';

Output:

TypeError: /Users/niftylettuce/Public/test/src/config/utilities.js: Cannot read property 'name' of undefined
    at /Users/niftylettuce/Public/test/node_modules/babel-plugin-lodash/lib/index.js:214:21
    at arrayEach (/Users/niftylettuce/Public/test/node_modules/lodash/_arrayEach.js:15:9)
    at forEach (/Users/niftylettuce/Public/test/node_modules/lodash/forEach.js:38:10)
    at PluginPass.ExportNamedDeclaration (/Users/niftylettuce/Public/test/node_modules/babel-plugin-lodash/lib/index.js:210:26)
    at newFn (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/niftylettuce/Public/test/node_modules/babel-traverse/lib/context.js:192:19)
Retsam commented 6 years ago

I'm seeing a very similar error when using this plugin in conjunction with babel-plugin-espower and babel-plugin-transform-es2015-spread. I boiled this down to as minimal an example as I could:

I'm transpiling this code:

import _ from "lodash";
t.true(_.isEqual("foo", "bar"))

With this .babelrc:

{
    "plugins": [
        "transform-es2015-spread",
        ["espower", {
            "patterns": ["t.true(value, [message])"]
        }],
        "lodash"
    ]
}
TypeError: example.js: Cannot read property 'length' of undefined
    at hasSpread (/path/to/project/node_modules/babel-plugin-transform-es2015-spread/lib/index.js:21:30)
    at PluginPass.CallExpression (/path/to/project/node_modules/babel-plugin-transform-es2015-spread/lib/index.js:92:14)
    at newFn (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/index.js:114:17)

It compiles fine if I remove any of the three plugins, or if I move the lodash plugin before espower. (Not a viable solution, however, for my real-use, as espower plugin is added by the ava testing library, and I don't think I can control the resulting ordering)

Versions:


I'm not sure if it's actually the same issue as @niftylettuce is seeing, but it's the exact same error message, so I thought I'd put it here first.

jdalton commented 6 years ago

Thanks for the added info. I'll mark this as a dup of #168.