question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module xxx

See original GitHub issue
  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: Windows Server 2016
  • Vetur version:
  • VS Code version:

Problem

The error message “cannot find module ‘components/models’” is displayed within vscode although the file is clearly there… When running the code with tsc no error is displayed.

image

Reproducible Case

Simply create a new Quasar project by running quasar create <project> as described here.

Additional info

Following the FAQ I tried to fix it but no luck. The things I’ve tried are:

  • All TS settings within Vetur:

image

  • Enable Vetur: Use Workspace Dependencies

image

  • Reinstall the Vetur extension

Files

models.ts

export interface Todo {
  id: number;
  content: string;
}

export interface Meta {
  totalCount: number;
}

CompositionComponent.vue

<template>
  <div>
    <p>{{ title }}</p>
    <ul>
      <li v-for="todo in todos" :key="todo.id" @click="increment">
        {{ todo.id }} - {{ todo.content }}
      </li>
    </ul>
    <p>Count: {{ todoCount }} / {{ meta.totalCount }}</p>
    <p>Active: {{ active ? 'yes' : 'no' }}</p>
    <p>Clicks on todos: {{ clickCount }}</p>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, computed, ref } from '@vue/composition-api';
import { Todo, Meta } from './models';

function useClickCount() {
  const clickCount = ref(0);
  function increment() {
    clickCount.value += 1
    return clickCount.value;
  }

  return { clickCount, increment };
}

function useDisplayTodo(todos: Todo[]) {
  const todoCount = computed(() => todos.length);
  return { todoCount };
}

export default defineComponent({
  name: 'CompositionComponent',
  props: {
    title: {
      type: String,
      required: true
    },
    todos: {
      type: (Array as unknown) as PropType<Todo[]>,
      default: () => []
    },
    meta: {
      type: (Object as unknown) as PropType<Meta>,
      required: true
    },
    active: {
      type: Boolean
    }
  },
  setup({ todos }) {
    return { ...useClickCount(), ...useDisplayTodo(todos) };
  }
});
</script>

Config

@quasar/app/tsconfig-preset/tsconfig-preset.json

{
  "compilerOptions": {
    "allowJs": true,
    // `baseUrl` must be placed on the extending configuration in devland, or paths won't be recognized
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    // Needed to address https://github.com/quasarframework/app-extension-typescript/issues/36
    "noEmit": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "strict": true,
    "target": "es6",
    // Quasar-defined webpack aliases
    "paths": {
      "src/*": ["src/*"],
      "app/*": ["*"],
      "components/*": ["src/components/*"],
      "layouts/*": ["src/layouts/*"],
      "pages/*": ["src/pages/*"],
      "assets/*": ["src/assets/*"],
      "boot/*": ["src/boot/*"]
    },
    // Forces quasar typings to be included, even if they aren't referenced directly
    // Removing this would break `quasar/wrappers` imports if `quasar`
    //  isn't referenced anywhere, because those typings are declared
    //  into `@quasar/app` which is imported by `quasar` typings
    "types": ["quasar"]
  },
  // Needed to avoid files copied into 'dist' folder (eg. a `.d.ts` file inside `src-ssr` folder)
  // to be evaluated by TS when their original files has been updated
  "exclude": ["/dist", ".quasar", "node_modules"]
}

ts.config.json

{
  "extends": "@quasar/app/tsconfig-preset",
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
  }
}

Thank you for your help.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:29 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
yoyo930021commented, Nov 20, 2020

maybe this is problem

image

Please follow #2377

5reactions
bekalshenoycommented, May 9, 2020

@ = ./src/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot find module XXX (typescript aliases)
I am using typescript and node. I want to change my import statements from import XX from "../../../XXX" into import XX ...
Read more >
Cannot find module 'xxx' or its corresponding type declarations.
I'm using typescript, It basically works, but it doesn't load the type declarations. Cannot find module 'xxx' or its corresponding type ...
Read more >
Debugging npm - "Error: Cannot find module xxx"
Detailed steps. Ensure the module is installed using the command: npm list package_name . This will need to be run in the project's...
Read more >
error ts2307: cannot find module or its corresponding type ...
I am having SOMETIMES an issue message when I run the command "npm run build:xxx" happens randomly.. ERROR in src/app/framework/services/svg2image/svg-to-image.
Read more >
nodejs express 启动报错:Error: Cannot find module 'xxx'
nodejs express 启动报错:Error: Cannot find module 'xxx',这是因为缺少模块的引用。 比如我在代码中使用了'express-session',但是却没有在 package.json 文件的 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found