custom-server-typescript
svg-components
with-absolute-imports
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/*"]
},
https://github.com/PaulPCIO/next.js-issues-svg-absolute-imports-tslint
uncomment lines in components/ImageExamples.tsx
import Absolute_CatSVG from 'svg/cat.svg'

#issue 2: RESOLVED

as for the tslinting part i ended up just adding an index.d.ts under my @types folder and then declaring the modules
declare module '*.png'
declare module '*.jpg'
declare module '*.jpeg'
declare module '*.svg'
declare module '*.gif'
I would like to work on this. @Timer , any advice on where I can start looking?
I would like to work on this. @Timer , any advice on where I can start looking?
This should be resolved, as i explained in my update it was just a declaration problem with typescript,
I had to define the declaration for images:
Update:
as for the tslinting part i ended up just adding an
index.d.tsunder my @types folder and then declaring the modulesdeclare module '*.png' declare module '*.jpg' declare module '*.jpeg' declare module '*.svg' declare module '*.gif'
For anyone else landing here from Google at 1.30am in the morning whilst trying to deploy a prototype for a pitch, the following format in the index.d.ts resulted in errors for my build:
declare module '*.png'
I had to declare the properties as such:
declare module "*.png" {
const value: any;
export default value;
}
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.ts in assets/svg and reexports the svgs (export { default as SvgThing } from './thing.svg') and import from that file instead of directly from the .svg files.
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.
Thank you! So far, this is the best solution
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
Most helpful comment
Update:
as for the tslinting part i ended up just adding an
index.d.tsunder my @types folder and then declaring the modules