The project was created using the following command:
vue create testtype3
Link to image: https://i.sstatic.net/vMuq0.png
App.vue:
<template>
<img alt="Vue logo" src="./assets/logo.png">
<img :src="MyIcon" />
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import MyIcon from './assets/logo.png';
export default defineComponent({
name: 'App',
components: {
},
setup(props, { emit }) {
return {
MyIcon
}
}
});
</script>
main.ts:
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
index.d.ts:
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
babel.config.js:
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
package.json:
{
"name": "testtype3",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.8.3",
"vue": "^3.2.13"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-plugin-typescript": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"@vue/eslint-config-typescript": "^9.1.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"file-loader": "^6.2.0",
"typescript": "~4.5.5"
}
}
tsconfig.json:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"useDefineForClassFields": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
vue.config.js:
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})
The App
displays a logo in two ways: passing a path String to an img
and by passing an imported MyLogo
to an img
. However, I get an error for the second approach:
TS2307: Cannot find module './assets/logo.png' or its corresponding type declarations.
<script lang="ts">
import { defineComponent } from 'vue';
import MyIcon from './assets/logo.png';
^^^^^^^^^^^^^^^^^^^
Removing the MyIcon
import and the img
element that uses MyIcon
results in npm run serve
running without problems.
A types
folder was created in the root directory with an added index.d.ts
, however the error persists.