I'm trying to translate a Vue project from JavaScript to TypeScript without using the class-style syntax.
Here are the steps I followed:
vue add typescript
I translated all my .vue
files in:
<script lang="ts">
export default {
-> export default Vue extend({
types.d.ts
with my custom types and imported it in the types
option of tsconfig.json
. However, when I'm running the application, I get this error:
Module parse failed: Unexpected token (23:16)
File was processed with these loaders:
* ../../../../.nvm/versions/node/v12.18.0/lib/node_modules/@vue/cli-service-global/node_modules/cache-loader/dist/cjs.js
* ../../../../.nvm/versions/node/v12.18.0/lib/node_modules/@vue/cli-service-global/node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| data() {
| return {
> todos: [] as Todo[]
| };
| },
It seems that the loaders the project is using do not recognize the TypeScript syntax. Do you have any idea how to resolve this issue?
Eventually, I found the issue. I was running the app using vue serve
instead of npm run serve
. For whatever reason, it solved it.