next.js: import svg (path must be a string or Buffer)
for me this example doesn’t work https://github.com/zeit/next.js/tree/master/examples/svg-components
npm install babel-plugin-inline-react-svg --save-dev
.babelrc:
{
"plugins": [
[
"module-resolver", {
"root": ["."],
"alias": {
"styles": "./styles"
},
"cwd": "babelrc"
}],
[
"wrap-in-js",
{
"extensions": ["css$"]
}
],
["inline-react-svg"]
],
"presets": [
"next/babel"
],
"ignore": []
}
and i get
Module build failed:
TypeError: C:/Users/.../src/components/header/View.js: path must be a string or Buffer
at TypeError (native)
at Object.fs.openSync (fs.js:641:18)
at fs.readFileSync (fs.js:509:33)
at PluginPass.ImportDeclaration (C:\Users\...\node_modules\babel-plugin-inline-react-svg\lib\index.js:63:50)
at newFn (C:\Users\...\node_modules\babel-traverse\lib\visitors.js:276:21)
tried with multiple sources of svg’s. There content looks fine
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 3
- Comments: 15 (1 by maintainers)
Not one that I can share. Its on a private repo. But the use case is very simple. I used the static export example (https://github.com/zeit/next.js/tree/master/examples/with-static-export) as a boilerplate. Added the inline-svg plugin. I then used it like this
Hope this helps
Strange, I already use relative paths and still have this issue…
https://www.npmjs.com/package/babel-plugin-module-resolver
i’m using the Linux subsystem on windows 10 and my app deployed via now also works fine