question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugin likely needs `filename` when used with babel's `transform`

See original GitHub issue

Hi, I’ve been working to upgrade Thumbtack’s design system to Babel 7. Got stuck at babel-plugin-inline-react-svg with the error “Path must be a string. Received undefined.” It failed because iconPath was undefined:

https://github.com/airbnb/babel-plugin-inline-react-svg/blob/7ba334c641d252e7d478ae941fe689946e18bbe9/src/index.js#L47-L48

This happened because I use babel.transform(code, opts). Previously, Babel would set filename: "unknown" in opts. This seems to have changed in Babel 7.

Here’s a commit with a failing test case: https://github.com/danoc/babel-plugin-inline-react-svg/commit/82d475926fc6d5866f255e0b306295a84ab5c2e9. Adding filename: test/fixtures/test-import-read-file.jsx to opts (the second argument) fixes the test case.

I don’t think this is a bug in babel-plugin-inline-react-svg, but these changes may be helpful:

  • Throw an error if iconPath is undefined (before dirname(iconPath)).
  • Update README example to include filename.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Oct 19, 2018

It seems like, altho you can use the API programmatically, the svgPath code kind of expects you’ll only use it on a file (ie, applyPlugin only takes a path).

I think the test case is great, but i think handling this properly might need a bit of refactoring. I’ll open a PR with your test case once I’ve got a solution.

0reactions
ljharbcommented, Oct 22, 2018

Fixed in #53.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/plugin-transform-classes
When extending a native class (e.g., class extends Array {} ), the super class needs to be wrapped. This is needed to workaround...
Read more >
babel-plugin-transform-import
Start using babel-plugin-transform-import in your project by running ... .js file will be require d relative from this plugin's path, likely ...
Read more >
How to use the babel-core.transformFileSync function in ...
To help you get started, we've selected a few babel-core.transformFileSync examples, based on popular ways it is used in public projects.
Read more >
Options · Babel 中文网
Some plugins may require the presence of the filename. ... The primary use case for this would be a chain of multiple transform...
Read more >
Understanding ASTs by Building Your Own Babel Plugin
readFile(fileName, function(err, data) { if(err) throw err; // convert from a buffer to a string var src = data.toString(); // use our plugin...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found