Vue-svg-loader: "Cannot find module" with Typescript

Created on 17 Jul 2018  路  2Comments  路  Source: visualfanatic/vue-svg-loader

Hi,

This vue-svg-loader is really useful and I used it successfully with some JS projects.
Now I'm trying to use it in a project with Nuxt and Typescript and I cannot make Typescript understand that my SVGs are Vue component.

I get this error: Cannot find module '../assets/icons/notification.svg'

The path is right, it compiles (with errors) and works well in dev mode, but then I can't build for prod because of the errors.

I tried adding this in my index.d.ts without success:

import Vue from 'vue';
declare module '*.svg' {
  export default Vue;
}

Do you know how I can fix that? Thanks!

Most helpful comment

Ok, I found a way to fix it 馃槃

I made a new file svg.d.ts (I have other typings in index.d.ts) and modified the declaration like this:

declare module '*.svg' {
  import Vue from 'vue';
  export default Vue;
}

I suggest you had an explanation in the README (eg: vue-svg-icon-loader).

All 2 comments

Ok, I found a way to fix it 馃槃

I made a new file svg.d.ts (I have other typings in index.d.ts) and modified the declaration like this:

declare module '*.svg' {
  import Vue from 'vue';
  export default Vue;
}

I suggest you had an explanation in the README (eg: vue-svg-icon-loader).

Thank you @Godefroy for reporting this!
I added the section with the solution in the docs:
https://vue-svg-loader.js.org/faq.html#how-to-use-this-loader-with-typescript

Was this page helpful?
0 / 5 - 0 ratings

Related issues

psulkava picture psulkava  路  3Comments

AasmundEndresen picture AasmundEndresen  路  5Comments

AtofStryker picture AtofStryker  路  3Comments

jpetko picture jpetko  路  5Comments

Peppe87 picture Peppe87  路  4Comments