Issue: svg-components with absolute imports not working
See original GitHub issueExamples bug report
Example name
custom-server-typescript svg-components with-absolute-imports
Describe the bug
with the svg-components and absolute import the svg’s are not found
[ error ] ./components/cowsay.tsx
Error: Cannot find module 'svg/cat.svg' from '/Users/Projects/Playground/next/components'
with tslint it does not see .jpg, .svg or any images as paths but instead as modules
Absolute Paths:
Cannot find module 'svg/cat.svg.ts(2307)
Cannot find module ‘images/pexels-photo.jpg’.ts(2307)
Relative Paths:
Cannot find module ‘…/assets/svg/cat.svg’.ts(2307)
Cannot find module ‘…/assets/images/pexels-photo.jpg’.ts(2307)
( as i side note i added paths to my tsconfig )
"paths": {
"images/*": ["assets/images/*"],
"svg/*": ["assets/svg/*"]
},
To Reproduce
https://github.com/PaulPCIO/next.js-issues-svg-absolute-imports-tslint
uncomment lines in components/ImageExamples.tsx
- https://github.com/PaulPCIO/next.js-issues-svg-absolute-imports-tslint/blob/e3b6490d2456abcf6c0f5f4caba081cc28662c82/components/ImageExamples.tsx#L4
- https://github.com/PaulPCIO/next.js-issues-svg-absolute-imports-tslint/blob/e3b6490d2456abcf6c0f5f4caba081cc28662c82/components/ImageExamples.tsx#L42
Expected behavior
- Expect SVG’s to import from absolute paths
Expect tslint to recognise image importations
Screenshots
#issue 1:
import Absolute_CatSVG from 'svg/cat.svg'

#issue 2: RESOLVED

System information
- OS: macOS
- Version of Next.js: 8.1.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
NextJS, Storybook, SVG and absolute import paths
There's an answer to a different problem that worked for me here. It might be because a conflict with Storybook's default SVG loader....
Read more >Why and How to Use Absolute Imports in React
Relative imports has some more problems. Pretty hard to refactor. It becomes worse as you get further deeper into it. You need to...
Read more >How to Import SVGs in a React and Vite app
Are you having difficulties importing SVGs into your React app? This is a problem that many developers face, especially when setting up a ......
Read more >Importing a Component
You can configure your application to support importing modules using absolute paths. This can be done by configuring a jsconfig.json or ...
Read more >Working with SVGs in React Native
The react-native-svg components use sentence case in naming to ... what users do on your web app, helping you troubleshoot issues faster.
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

Not sure if it is related but I recently stumbled upon this while using Next.js absolute import with babel-plugin-inline-react-svg and expected
import SvgThing from '@/assets/svg/thing.svg'magically works. It won’t.I guess because it is Babel related, not Webpack related so absolute import won’t work out of the box. Also this
My solution is to create a
index.tsinassets/svgand reexports the svgs (export { default as SvgThing } from './thing.svg') and import from that file instead of directly from the.svgfiles.If I use this I get the following error:
index.ts: pass.get(...) is not a function