Skip to content

App crashing with "Cannot read property 'name' of undefined" after installing plugin #92

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

Closed
tremby opened this issue Oct 29, 2020 · 2 comments · Fixed by #93
Closed

Comments

@tremby
Copy link
Contributor

tremby commented Oct 29, 2020

I'd like to use this in my Nextjs project, where I'm using Typescript.

All I've done so far is install the plugin and add it under plugins to my .babelrc file. The app now crashes on start, with the message Cannot read property 'name' of undefined.

The file it references is one of mine but it seems to be a complete red herring: there's nothing in that file remotely to do with SVGs, and it doesn't look up the name property of anything. I haven't even added any statements importing SVG files yet.

I scanned through the source code and traced the error to babel-plugin-inline-react-svg/lib/index.js in the ExportNamedDeclaration function, specifically this line:

        if (node.specifiers.length > 0 && node.specifiers[0].local.name === 'default') {

I sprinkled logs around this, and this is definitely the line that's crashing. In this case node.specifiers.length is 1, but that first item has no local property. I get a lot of output when dumping this (I guess many instances of this are running in parallel? Most crash, a few don't since they have length 0 and so it doesn't try to look up .local.name for those), and here's one of the node.specifiers arrays, as rendered by console.log:

[
  Node {
    type: 'ExportNamespaceSpecifier',
    start: 685,
    end: 699,
    loc: SourceLocation { start: [Position], end: [Position] },
    exported: Node {
      type: 'Identifier',
      start: 690,
      end: 699,
      loc: [SourceLocation],
      name: 'Constants',
      leadingComments: undefined,
      innerComments: undefined,
      trailingComments: undefined
    },
    leadingComments: undefined,
    innerComments: undefined,
    trailingComments: undefined
  }
]

One tutorial told me to install babel-plugin-module-resolver. I've tried both with and without that and it's no different. My .babelrc looks like this:

{
  "presets": ["next/babel"],
  "plugins": [
    ["styled-components", { "ssr": true }],
    ["module-resolver", {"root": ["."]}],
    "inline-react-svg",
  ]
}

I also tried without the styled-components plugin; no change there either.

I'm using Typescript 4.0.5, Babel 7.12.3, node 12.18.1.

@tremby
Copy link
Contributor Author

tremby commented Oct 29, 2020

I found a fix; will submit a PR...

tremby added a commit to tremby/babel-plugin-inline-react-svg that referenced this issue Oct 29, 2020
tremby added a commit to tremby/babel-plugin-inline-react-svg that referenced this issue Oct 29, 2020
tremby added a commit to tremby/babel-plugin-inline-react-svg that referenced this issue Oct 29, 2020
@tremby
Copy link
Contributor Author

tremby commented Oct 29, 2020

Would love to see a release if possible!

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

Successfully merging a pull request may close this issue.

1 participant