I'm currently working on a Vue 3 project using Vitesse (which is based on Vite). I created a custom type called ProductData
in my src/types.ts
file. However, when I try to use this type in one of my pages, the page fails to load and I see multiple console errors stating
SyntaxError: import not found: ProductData
. I have double-checked the import path, ensured that the type is exported correctly, and even experimented with importing from different locations within ts files, but the issue remains.
Interestingly, I don't encounter any problems importing these types in my store
files, only in *.vue files. Any suggestions or insights? I came across this post which mentioned making changes to shims.d.ts
and tsconfig.json
, but implementing those adjustments didn't resolve the problem.
EDIT: Apologies for missing out on sharing my tsconfig.json
. Here it is including additions made by @flydev:
// Additional configurations inspired by https://stackoverflow.com/questions/63724523/how-to-add-typescript-to-vue-3-and-vite-project
{
"compilerOptions": {
"baseUrl": ".",
"module": "ESNext",
"target": "ESNext",
"lib": [
"DOM",
"ESNext"
],
"useDefineForClassFields": true,
"strict": true,
"esModuleInterop": true,
"incremental": false,
"skipLibCheck": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"importHelpers": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"noEmit": true,
"types": [
"vite/client",
"vite-plugin-pages/client",
"vite-plugin-vue-layouts/client"
],
"paths": {
"~/*": [
"src/*"
]
}
},
"include": [
"src/**/*.ts",
"src/**/*.js",
"src/**/*.vue"
],
"exclude": [
"dist",
"node_modules"
]
}
EDIT 2: Upon switching from Firefox to Chrome and inspecting types.ts
under sources
, I noticed that the file was empty. The error message has also changed to possibly provide more useful information:
SyntaxError: The requested module '/src/types.ts' does not provide an export named 'JsonResponse'
.