Plugin likely needs `filename` when used with babel's `transform`
See original GitHub issueHi, 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:
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
isundefined
(beforedirname(iconPath)
). - Update README example to include
filename
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Fixed in #53.