Nuxt (typescript) - cannot resolve file logo.svg

Component:

<template>
<img src="@/assets/svg/logo.svg />
</template>

Gives an error Cannot resolve file and directory "@". I have used fake webpack.config.json and pointed WebStorm to it:

const path = require('path')

module.exports = {
resolve: {
// for WebStorm
alias: {
'@': path.resolve(__dirname)
}
}
}

tsconfig.json:

{
"compilerOptions": {
"experimentalDecorators": true,
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"lib": ["esnext", "esnext.asynciterable", "dom"],
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"~/*": ["./*"],
"@/*": ["./*"]
},
"types": ["@types/node", "@nuxt/types", "nuxt-i18n"]
},
"exclude": ["node_modules"]
}

I've tried to use "~@/assets/svg/logo.svg", but still WebStorm complains about it, though it works with Nuxt, i can see my logo.svg.

If i use:

<img :src="require('~/assets/svg/logo.svg')" />

it works.

1

Please sign in to leave a comment.