Choose one: is this a π bug report or π feature request?
πBug
If an inline SVG (in HTML) contains the use tag, the whole SVG will be replaced by the string undefined
No config
β― echo '<!DOCTYPE html><svg><use xlink:href="./file.svg"></svg>' > index.html
β― parcel build index.html
β¨  Built in 992ms.
dist/index.html    25 B    938ms
β― cat dist/index.html
<!DOCTYPE html>undefined 
Output should be unchanged
Output is:
<!DOCTYPE html>undefined 
Strange thing is that parcel doesn't check for the file at all during parcel build but will fail during parcel watch:
π¨  ..../index.html: Cannot resolve dependency './file.svg' at    at Resolver.resolve (/usr/local/lib/node_modules/parcel-bundler/src/Resolver.js:73:17)
This: https://css-tricks.com/svg-use-external-source/
<!DOCTYPE html><svg><use xlink:href="./file.svg"></svg>
| Software         | Version(s) |
| ---------------- | ---------- |
| Parcel           | 1.6.2
| Node             | 5.6.0
| npm/Yarn         | 5.7.1
| Operating System | macOS 10.13.3
Related to https://github.com/svg/svgo/issues/921 ?
Sent with GitHawk
It doesn't look like it; that one drops href, this bug replaces the whole <svg> with undefined, regardless of other content
Could u open up an issue in the htmlnano repo? As I donβt think this is a parcel bug
Sent with GitHawk
Indeed, as long as it's also tracked here
Edit: I appended it to https://github.com/posthtml/htmlnano/issues/47#issuecomment-372699634 since a solution for that should also keep in mind this other bug.
SVGO doesn't handle xlink:href attributes:
> node_modules/.bin/svgo -s '<svg><use xlink:href="./file.svg" /></svg>'
Error in parsing SVG: Unbound namespace prefix: "xlink"
So there is nothing I can fix in htmlnano, unfortunately. Though, I'd suggest replacing xlink:href, which is deprecated, with href.
Probably that error is due to the lack of the xlink namespace definition. I probably canβt use href without the namespace with the same browser compatibility. Iβll try. 
Probably that error is due to the lack of the xlink namespace definition
That was indeed the case:
β― svgo --version
1.0.3
β― svgo -s '<svg><use xlink:href="./file.svg" /></svg>'
Error in parsing SVG: Unbound namespace prefix: "xlink"
Line: 0
Column: 36
Char: >
β― svgo -s '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><use xlink:href="./file.svg" /></svg>'
<svg xmlns:xlink="http://www.w3.org/1999/xlink"><use xlink:href="./file.svg"/></svg>
This still seems to be a bug in parcel@master, even if htmlnano 0.1.7 fixed the output to error
β― npm i parcel-bundler/parcel
β― npm ls parcel-bundler htmlnano svgo
/
βββ¬ [email protected]  (github:parcel-bundler/parcel#c469751e145a426fee2f1de27ccb2a747c7f5d1e)
  βββ¬ [email protected]
  β βββ¬ [email protected]
  β   βββ [email protected] 
  βββ¬ [email protected] 
    βββ [email protected]  extraneous
β― echo '<!DOCTYPE html><svg><use xlink:href="./file.svg"></svg>' > index.html
β― ./node_modules/.bin/parcel build index.html
β¨  Built in 68ms.
dist/index.html    25 B    4ms
β― cat dist/index.html
<!DOCTYPE html>undefined
β― node -e 'require("htmlnano").process(require("fs").readFileSync("index.html")).then(result => console.log(result.html));'
(node:45780) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error in parsing SVG: Unbound namespace prefix: "xlink"
Line: 0
Column: 34
Char: >
(node:45780) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
β― ./node_modules/.bin/svgo index.html -o -
Error in parsing SVG: Unbound namespace prefix: "xlink"
Line: 0
Column: 49
Char: >
Neat. --no-cache shows the error. Without it it's undefined
β― npm i parcel-bundler
β― ./node_modules/.bin/parcel --version
1.6.2
β― ./node_modules/.bin/parcel build index.html
β¨  Built in 58ms.
dist/index.html    180 B    3ms
β― ./node_modules/.bin/parcel build index.html --no-cache
π¨  Error in parsing SVG: Unbound namespace prefix: "xlink"
Line: 0
Column: 79
@bfred-it cache only keeps in mind the version of parcel, not the dependencies so it makes sense. Can we close this issue?
If using the cache causes the bug I don't think the issue can be closed.
Can you try on your machine? These are the 5 commands to run
echo '<!DOCTYPE html><svg><use xlink:href="./file.svg"></svg>' > index.html
npm i parcel-bundler
./node_modules/.bin/parcel --version
./node_modules/.bin/parcel build index.html
./node_modules/.bin/parcel build index.html --no-cache
Ok I deleted .cache and now it fails even without --no-cache π 
I found another SVG bug related to parcel build though, I'll open a new issue.
SVGO doesn't handle
xlink:hrefattributes:> node_modules/.bin/svgo -s '<svg><use xlink:href="./file.svg" /></svg>' Error in parsing SVG: Unbound namespace prefix: "xlink"So there is nothing I can fix in
htmlnano, unfortunately. Though, I'd suggest replacingxlink:href, which is deprecated, withhref.
Thanks, it works.
Most helpful comment
Thanks, it works.