Skip to content
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

Use require('vue') for non-ESM usage #966

Open
octref opened this issue Nov 15, 2018 · 0 comments
Open

Use require('vue') for non-ESM usage #966

octref opened this issue Nov 15, 2018 · 0 comments
Labels

Comments

@octref
Copy link
Member

octref commented Nov 15, 2018

For the following Vue file

export default {
  props: {
    foo: String
  },
  data() {
    return {
      /** @type { import("./types").Item[] } */
      items: []
    }
  },
  methods: {
    add(text) {
      const item = { id: this.items.length, text, done: false }

      return this.items.push(item)
    }
  },
  created() {
    this.add(123443434343434343434)
  }
}

You might get the following error:

[Trace - 9:40:57 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///Users/znck/Workspace/Experiments/type-why/src/components/HelloWorld.vue",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 7,
                    "character": 18
                },
                "end": {
                    "line": 7,
                    "character": 24
                }
            },
            "severity": 1,
            "message": "Cannot find name 'import'."
        },
        {
            "range": {
                "start": {
                    "line": 7,
                    "character": 24
                },
                "end": {
                    "line": 7,
                    "character": 25
                }
            },
            "severity": 1,
            "message": "'}' expected."
        }
    ]
}

That is because we add import Vue from 'vue' on top of your script file. For people not using TS or ESModules, we should use const Vue = require('vue') instead.

@octref octref added the bug label Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant