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

[v0.3.0] cannot read property 'name' of undefined #58

Closed
shreyasminocha opened this issue Jul 2, 2018 · 7 comments
Closed

[v0.3.0] cannot read property 'name' of undefined #58

shreyasminocha opened this issue Jul 2, 2018 · 7 comments
Labels

Comments

@shreyasminocha
Copy link

shreyasminocha commented Jul 2, 2018

.babelrc:

{
    "sourceMap": true,
    "presets": ["env"],
    "plugins": [
        ["transform-builtin-extend", {"globals": ["RegExp"]}],
        "add-module-exports",
        "transform-es2015-modules-umd"
    ],
    "moduleId": "VerEx"
}
 babel index.js 
TypeError: index.js: Cannot read property 'name' of undefined
    at NodePath._getKey (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/family.js:148:23)
    at NodePath.get (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/family.js:138:17)
    at NodePath._getPattern (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/family.js:192:21)
    at NodePath.get (/usr/local/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/family.js:140:17)
   at AssignmentExpression (/Users/shreyasminocha/dev/forks/repo/node_modules/babel-plugin-add-module-exports/lib/index.js:19:23)
    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)
@ljharb
Copy link

ljharb commented Jul 2, 2018

I'm also seeing this on a number of modules where greenkeeper has tried to update the plugin.

Separately, it seems like v0.3.0 won't transpile export default foo to module.exports =, based on "However, the plugin doesn't change the pure-esmodule" - its primary/sole purpose is to add module.exports to pure ES Modules. Am I missing something?

@shreyasminocha
Copy link
Author

@ljharb

However, the plugin doesn't change the pure-esmodule. this plugin makes changes only when exists exports.default

My understanding is that they meant it wouldn't transpile export foo but would transpile export default foo.

Moreover, that line has been in the README since before v0.3.0.

@Macil
Copy link

Macil commented Jul 2, 2018

I'm having this issue too in Macil/react-save-refs#9. You can reproduce the issue by checking out the "greenkeeper/babel-plugin-add-module-exports-0.3.0" branch of react-save-refs, and then run yarn.

@59naga 59naga added the v0.3.0 label Jul 2, 2018
@59naga
Copy link
Owner

59naga commented Jul 2, 2018

It was a missing check of simple AssignmentExpression. The following will fail.

let foo
foo = "default-entry" // TypeError: index.js: Cannot read property 'name' of undefined
export default foo

On line 10 of the plugin, access to the undefined property of AST of 2nd line. this issue is fixed soon.

@59naga
Copy link
Owner

59naga commented Jul 2, 2018

Applied it as v0.3.1.

@loganfsmyth
Copy link

@59naga FYI, you can reduce that code a bit if you want, to

if (path.get('left').matchesPattern("exports.default")) {

@59naga
Copy link
Owner

59naga commented Jul 2, 2018

Nice, I'll apply it

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

Successfully merging a pull request may close this issue.

5 participants