0

I'm using TypeScript with Vue and I'm facing this error from my main.ts file.

Error Information

Here's my shims-vue.d.ts file:

/* eslint-disable */
declare module "*.vue" {
    import type { DefineComponent } from "vue";
    const component: DefineComponent<{}, {}, any>;
    export default component;
}

My App.vue is just a simple template without any script or style:

<template lang="pug">
router-view
</template>

I do not want to do the "noImplicitAny": false in tsconfig.js, so is there any solution to this problem apart from that?

Also, same thing happens in test cases,

import { shallowMount } from "@vue/test-utils";
import Layout from "@/plugin/layout/Layout.vue";

describe("Layout.vue", () => {
    it("renders props.msg when passed", () => {
        const wrapper = shallowMount(Layout);
        expect(wrapper.text()).toMatch("sidebar");
    });
});

Error is: enter image description here

7
  • Does the error occur only inside tests? What command do you run to get error? vue-cli build or vue-cli test? Commented Jan 28, 2022 at 20:46
  • Did you try to add script to App? They aren't necessarily the same errors, it could be that Jest can't resolve @/ Commented Jan 28, 2022 at 20:48
  • This problem appears in both App.vue while starting the app in development environment, and while running the tests using vue-cli-service test:unit. Commented Jan 28, 2022 at 20:49
  • And I tried with the relative path as well instead of @, that didn't seem to work either. Commented Jan 28, 2022 at 20:51
  • Do you have webpack.config.js in your project? Commented Jan 29, 2022 at 13:01

1 Answer 1

1

The reason for the error is that you named your vue file App.vue.js.

The solution: rename App.vue.js to App.vue

Sign up to request clarification or add additional context in comments.

2 Comments

No, the file name is App.vue only. I'm not sure why the App.vue.js error comes.
Ah, that was my mistake. Sure, webpack aliases the file to *.vue.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.