vetur: SFC without a script tag show an error when trying to import

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: macOS
  • Vetur version:0.18.1
  • VS Code version: 1.33.0

Problem

Components without a script tag and an export are flagged with an error:

File ‘…import_example/src/components/Simple.vue’ is not a module. Vetur(2306)

<!-- src/components/Simple.vue -->
<template>
  <h1>No script tag in this component</h1>
</template>
// App.vue
// ...
import Simple from "./components/Simple.vue";
// ...

Reproducible Case

Here is the diff to a brand new project created with vue-cli:

diff --git a/src/App.vue b/src/App.vue
index 7633616..04a51d9 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,17 +1,17 @@
 <template>
   <div id="app">
     <img alt="Vue logo" src="./assets/logo.png">
-    <HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
+    <Simple/>
   </div>
 </template>
 
 <script lang="ts">
 import { Component, Vue } from 'vue-property-decorator';
-import HelloWorld from './components/HelloWorld.vue';
+import Simple from "./components/Simple.vue";
 
 @Component({
   components: {
-    HelloWorld,
+    Simple,
   },
 })
 export default class App extends Vue {}
diff --git a/src/components/Simple.vue b/src/components/Simple.vue
new file mode 100644
index 0000000..a7ad133
--- /dev/null
+++ b/src/components/Simple.vue
@@ -0,0 +1,3 @@
+<template>
+  <h1>No script tag in this component</h1>
+</template>

Here is the repo that shows the problem:

https://github.com/uri/vetur-import-example

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 44
  • Comments: 43 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Until this is fixed adding the following worked for me:

<script>
export default {}
</script>

As @mpvosseller suggested, adding below at the bottom of the file fixes the problem.

<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
    //
});
</script>

NB: Am using TypeScript. But js counterpart should work just fine

And Vetur show the same error if you split code into files like :

<template>
  <div class="logout">
    Logout !
  </div>
</template>

<script src="./logout.js"></script>
<style scoped lang="scss" src="./logout.scss"></style>

Output Vetur ...logout.vue' is not a module. Vetur(2306) [1, 1]

Any chance we could see a fix here soon?

Updated to 0.19.5 (vscode 1.33.1) and the issue went away.

Probably because templateInterpolationService has been disabled. Try adding the following setting in VSCode, do you see the problem again?

  "vetur.experimental.templateInterpolationService": true,

April 2020 This error/problem is still unresolved. Please fix the error message appearing needlessly.

Second that. Error still showing for importing .vue files with or without script tag. Doesn’t matter. In my case I’m importing it inside a script tag with lang set to ts, since I’m using typescript.

A workaround that does not involve empty exports for scenario’s in which you do have a script tag with a src attribute set to the js/ts file, is the following.

<script lang="ts">
import script from './script';
export default script;
</script>

Updated to 0.19.5 (vscode 1.33.1) and the issue went away.

Probably because templateInterpolationService has been disabled. Try adding the following setting in VSCode, do you see the problem again?

  "vetur.experimental.templateInterpolationService": true,

Love you man, I don’t know how you found this. They should update the docs

If anyone can test #1806?

  1. compile
git clone https://github.com/yoyo930021/vetur.git
git checkout fix-SFC-no-script
yarn
cd server && yarn && cd ..
yarn compile
  1. set the vetur config to using it vetur.dev.vlsPath set to <projectUrl>/server in vscode config.

PS. https://github.com/vuejs/vetur/blob/master/.github/CONTRIBUTING.md

please fix this bug, it is very annoying

Please, fix it sooner than “never”. It’s really annoying to add this to SVG component icons.

Wait for #1806 I believe coming soon

My fault, I’ve write vue-shims.d.ts myself with

declare module "*.vue" {
  import { ComponentPublicInstance } from "vue";
  const Component: ComponentPublicInstance;
  export default Component;
}

and I updated it to

declare module "*.vue" {
  import { ComponentPublicInstance } from "vue";
  const Component: ComponentPublicInstance | {};
  export default Component;
}

and things goes well.

Thanks for response.

Hi anyone, I publish self-maintenance vscode extension. This extension will be maintained until Vetur is reactivated.

https://marketplace.visualstudio.com/items?itemName=yoyo930021.vuter

I added this to my .vscode/settings.json and restarted vscode.

"vetur.experimental.templateInterpolationService": true

This fixed the issue for me.

@yoyo930021 tested. LGTM!

@uri I fetched your example project and noticed the error.

Although updating to 0.19.5 eliminated the Vetur(2306) error on my project, the components have the <script> tag. Adding a note to my initial post.

I came across the same problem. Then rollback to 0.18 solving it…

workaround: just add a empty class then resolve.

– but it still got error when import script file.

Same. Even with functional components. eg:

<template functional>
    <i class="pe-7s-attention fa-4x text-warning"></i>
</template>

I think it’s since the VSCode update