Open fregante opened 3 years ago
If those 3 errors weren't enough, just moving the SVG file to the same directory changes the error a 4th time 🎉
import Alert from './alert.svg';
console.log(Alert);
🚨 Build failed.
Error: The expression evaluated to a falsy value:
(0, _assert().default)(typeof v === 'string')
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
(0, _assert().default)(typeof v === 'string')
at assertString (./node_modules/@parcel/packager-js/node_modules/@parcel/scope-hoisting/lib/utils.js:156:25)
at ./node_modules/@parcel/packager-js/node_modules/@parcel/scope-hoisting/lib/link.js:159:42
at enter (./node_modules/@parcel/core/lib/Graph.js:547:16)
at enter (./node_modules/@parcel/core/lib/Graph.js:547:16)
at enter (./node_modules/@parcel/core/lib/Graph.js:547:16)
at walk (./node_modules/@parcel/core/lib/Graph.js:382:26)
at walk (./node_modules/@parcel/core/lib/Graph.js:403:22)
at walk (./node_modules/@parcel/core/lib/Graph.js:403:22)
at walk (./node_modules/@parcel/core/lib/Graph.js:403:22)
at Graph.dfs (./node_modules/@parcel/core/lib/Graph.js:427:12)
Side note: I really wish Parcel showed more information about the code it's evaluating, because Asset has no content
tells me nothing about where to find the issue. I had to delete 99% of my repository to find it.
I'm running into the issue from the first reply. Blew away yarn.lock
and added:
"resolutions": {
"@parcel/scope-hoisting": "2.0.0-nightly.417"
},
Neither worked.
So this is how it should work:
{
"extends": ["@parcel/config-default"],
"transformers": {
"*.svg": ["@parcel/transformer-svg-react"]
}
}
{
"dependencies": {
"@parcel/transformer-svg-react": "^2.0.0-nightly.2039",
"@primer/octicons": "^11.0.0",
"parcel": "^2.0.0-nightly.415",
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
}
import Alert from "@primer/octicons/build/svg/archive-24.svg";
console.log(Alert());
But we don't really run Babel (including jsx) over node_modules, so I'm currently getting an SyntaxError
from Babel.
This check prevents node_modules: https://github.com/parcel-bundler/parcel/blob/a839a03f93607c1744ce62e6f95f98d0635700f4/packages/transformers/babel/src/jsx.js#L40-L42
And this check should definitely be updated to use asset.type
instead of the filename extension (because this was once a svg file, but asset.type
is actually "jsx"
already):
Forgot to add that I’m using the new JSX transformer in React, if that affects anything.
If those 3 errors weren't enough, just moving the SVG file to the same directory changes the error a 4th time 🎉
import Alert from './alert.svg'; console.log(Alert);
🚨 Build failed. Error: The expression evaluated to a falsy value: (0, _assert().default)(typeof v === 'string') AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value: (0, _assert().default)(typeof v === 'string') at assertString (./node_modules/@parcel/packager-js/node_modules/@parcel/scope-hoisting/lib/utils.js:156:25) at ./node_modules/@parcel/packager-js/node_modules/@parcel/scope-hoisting/lib/link.js:159:42 at enter (./node_modules/@parcel/core/lib/Graph.js:547:16) at enter (./node_modules/@parcel/core/lib/Graph.js:547:16) at enter (./node_modules/@parcel/core/lib/Graph.js:547:16) at walk (./node_modules/@parcel/core/lib/Graph.js:382:26) at walk (./node_modules/@parcel/core/lib/Graph.js:403:22) at walk (./node_modules/@parcel/core/lib/Graph.js:403:22) at walk (./node_modules/@parcel/core/lib/Graph.js:403:22) at Graph.dfs (./node_modules/@parcel/core/lib/Graph.js:427:12)
It gives the same error to me too when trying to import an SVG. Is there a fix for this?
🐛 bug report
I can't import an SVG as a React component using https://github.com/parcel-bundler/parcel/pull/4108
🎛 Configuration (.babelrc, package.json, cli command)
🤔 Expected Behavior
No error.
Alert
should be a React component😯 Current Behavior
One of these 3 errors, at random
💁 Possible Solution
🔦 Context
I'm just trying to use https://github.com/parcel-bundler/parcel/pull/4108, as is, to import SVG files and use them as React(ish) components.
💻 Code Sample
Repro.zip
🌍 Your Environment