Skip to content

error: File App.vue is not a module.Because I separated my ts into separate files. #1720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sengmitnick opened this issue Jun 30, 2018 · 14 comments

Comments

@sengmitnick
Copy link

sengmitnick commented Jun 30, 2018

Version

3.0.0-rc.3

Reproduction link

https://github.com/bobmoff/vue-cli-not-a-module

Steps to reproduce

yarn build

What is expected?

Successful compilation

What is actually happening?

ERROR in /Users/smk17/VsCode/hello-world/src/main.ts
3:17 File '/Users/smk17/VsCode/hello-world/src/App.vue' is not a module.


I extracted ts to App.ts in App.vue and introduced it in the following way:

<script src="./App.ts"></script>
@Akryum
Copy link
Member

Akryum commented Jun 30, 2018

May be related to #1576

@Akryum Akryum added bug scope: typescript needs team repro We acknowledged your report and will soon try to reproduce it labels Jun 30, 2018
@sengmitnick
Copy link
Author

@Akryum Little relationship
Can be introduced by the following method,but none of this passes:<script src =“./ AppJs.ts”> </ script><script lang="ts" src="./AppJs.ts"></script><script lang="ts" src="./AppJs"></script>

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

@ChristianStornowski
Copy link

It could be a problem with

.vue and .(j|t)s are configured to be resolved via webpack without including an extension. Therefor App.(j|t)s and App.vue could be mixed up.

@sengmitnick
Copy link
Author

@LinusBorg
Copy link
Member

@sengmitnick the linked reproduction does not contain a typescript project, it's in fact a repository used for another (invalid) bug report before.

Can you please share the right repository?

@LinusBorg LinusBorg added needs reproduction This issue is missing a minimal runnable reproduction, provided by the author and removed needs team repro We acknowledged your report and will soon try to reproduce it labels Jul 3, 2018
@bobmoff
Copy link

bobmoff commented Jul 3, 2018

Heres a link: https://github.com/bobmoff/vue-cli-not-a-module

Only change I have made is to move the script content out from HelloWorld.vue into the a new file named HelloWorld.ts and then added src="./HelloWorld" to the script tag in the .vue file.

Been struggling with this for 2 days now trying to convert a project from the old webpack templates to the new cool vue-cli scaffolding and not understanding why stuff is so broken.

The error I am getting in this example is:

ERROR in /Users/bobmoff/Projects/vue-cli-not-a-module/src/views/Home.vue
10:24 File '/Users/bobmoff/Projects/vue-cli-not-a-module/src/components/HelloWorld.vue' is not a module.
     8 | <script lang="ts">
     9 | import { Component, Vue } from 'vue-property-decorator';
  > 10 | import HelloWorld from '@/components/HelloWorld.vue'; // @ is an alias to /src
       |                        ^
    11 |
    12 | @Component({
    13 |   components: {

It doesn't seem to matter if i change to
export { default } from './HelloWorld'

or

import HelloWorld from './HelloWorld'
export default HelloWorld

inside the script tag

Any help is appreciated :)

Edit: Selected features when creating the project: Babel, Typescript, Router, CSS Pre-processsors

@bobmoff
Copy link

bobmoff commented Jul 3, 2018

If I change the name of the .ts file from HelloWorld.ts to HelloWorldCode.ts and use the
export { default } from './HelloWorldCode'
inside the script tag. .. it works.. :/

@sengmitnick
Copy link
Author

@bobmoff Quote your recurring link directly
@LinusBorg Can refer to the recurring link shared by bobmoff
Yes, it can now be referenced and exported within the script.For example, you can do this like:

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

@LinusBorg LinusBorg added needs team repro We acknowledged your report and will soon try to reproduce it and removed needs reproduction This issue is missing a minimal runnable reproduction, provided by the author needs team repro We acknowledged your report and will soon try to reproduce it labels Jul 4, 2018
@LinusBorg
Copy link
Member

This is definitely the same issue as #1576 so I will close this isse in favor of that older issue so we keep the discussion in one place.

Please add any further comments to #1576

@vuejs vuejs locked and limited conversation to collaborators Jul 4, 2018
@vuejs vuejs unlocked this conversation Jul 4, 2018
@herboys
Copy link

herboys commented Apr 26, 2019

why? xxxx.vue' is not a module

@austinhallett
Copy link

For anyone running into this issue in 2022;

{
  "compilerOptions": {
    "target": "ESNEXT",
    "module": "ESNext",
    "moduleResolution": "Node",
    "importHelpers": true,
    "lib": ["ESNext", "ESNext.AsyncIterable", "DOM"],
    "esModuleInterop": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noEmit": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["./*"],
      "@/*": ["./*"]
    },
    "types": ["@nuxt/types", "@nuxtjs/axios", "@types/node","@nuxtjs/vuetify","@nuxt/vue-app",]
  },
  "include": ["*.vue", "*.ts"],
  "exclude": ["node_modules", ".nuxt", "dist"]
}

I had to add the 'include' list to my tsconfig.json for nuxt app

@ilearnio
Copy link

ilearnio commented Sep 4, 2022

As it appears the script section has to export something

<script lang="ts">
export default {}
</script>

yungwenpeng added a commit to yungwenpeng/vue-dashboard-example that referenced this issue Jan 4, 2023
1. Cannot find module '../views/AboutView.vue' or its corresponding type declarations.
   disable VSCode's built-in TS language service
   Refer to : https://vuejs.org/guide/typescript/overview.html#volar-takeover-mode
2. Property 'env' does not exist on type 'ImportMeta'.
   Refer to : https://vitejs.dev/guide/features.html#client-types
3. src/App.vue.ts is not listed within the file list of project tsconfig.vitest.json
   Refer to : vuejs/vue-cli#1720 (comment)
@Brun00liveira
Copy link

Lev

@AleksKamb
Copy link

As it appears the script section has to export something

<script lang="ts">
export default {}
</script>

<script setup></script>
Also does the job it seems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants