I have created the most basic app to test this issue, not sure if I haven't configured something right, but the issue is that importing a typescript file into my .vue component will create no error and the compiler can find it, however when typing npm run serve an error will appear saying Can't resolve '@logic/enemy-repository' in '~\enemytest\src\views. Have recreated the app many times with diffrent configurations but still the same issue. Any ideas?
This is all being done in VS Code, Vue.js 3 and on windows. Just to note:
I'm referencing like so
import EnemyRepository from '@logic/enemy-repository'Doing relative referencing of the file causes no issue such as
import EnemyRepository from '../logic/enemy-repository'Doing the import from the route absolutely also works
import EnemyRepository from '@/logic/enemy-repository'Because of this the issue is most likely to do with the tsconfig.json file. My paths and baseurl are set up like so...
"baseUrl": ".", "paths": { "@/*": [ "src/*" ], "@logic/*": ["src/logic/*"], },
Steps to recreate:
- vue create enemytest
- Manually select features
- Babel, Typescript, Router, vuex, linter/formatter selected.
- 3.x
- USe class-style component syntax
- Use babel alongside typescript
- Use history mode
- ESLint with error prevention only
- Lint on save
- In dedicated config file
- Open in vs code.
- Create a new file in folder structure /src/loci/enemy-repository.ts and export method.
- Import repository into HomeView.vue.
- In tsconfig.json add a path new item to paths "@logic/": ["src/logic/"],
- Type in console npm run serve
- Error shows in terminal 'Module not found: Error: Can't resolve '@logic/enemy-repository' in '~\enemytest\src\views''
Have attached a repo here GitHub Repo
@/logic/whatever?vite.config.jsorwebpack.config.js(or.ts), depending on whether you use@vue/cliorvite@vue/cli).