Skip to content

Import *.vue files without extensions and handles paths in tsconfig #213

Closed
@samrg472

Description

@samrg472

Versions:

  • VSCode 1.12 and 1.13-insider (reproducible in both versions)
  • Vetur 0.6.10
  • Typescript 2.3.2

When opening a .vue file that hasn't been opened then false errors will be reported.
Issues:

  • Cannot find name 'require'.
  • Does not detect that experimentalDecorators is set to true in tsconfig.json but it is reported as though it is disabled.
  • Importing requires the .vue extension (tsc compiles fine without the .vue extension)
  • When importing aliases (using paths from tsconfig.json) it reports module not found

These issues do not occur in normal *.ts files and there aren't any compiler errors. The workaround is to restart VSCode with the file opened, and these issues no longer appear until it is closed and opened again.

home.vue (template and style tags removed)

<script lang="ts">
  import Component from 'vue-class-component';
  import Vue from 'vue';

  // const Sidebar = require('../components/sidebar.vue').default; // Error require not found
  import Sidebar from '../components/sidebar'; // Error module not found (need the .vue extension to workaround)
  import settings from 'settings'; // Error module not found (need to import with relative paths to workaround)

  @Component({ // Error experimentalDecorators are disabled and needs to be set
    components: {
      Sidebar
    }
  })
  export default class Home extends Vue {
  }
</script>

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "noImplicitAny": false,
    "sourceMap": true,
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "outDir": "dist",
    "baseUrl": ".",
    "rootDirs": [
      "../common",
      "./src/main",
      "./src/renderer"
    ],
    "paths": {
      "pm_common": ["../common"],
      "settings": ["./src/main/settings"]
    }
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions