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.

Weird "Vue is not defined" error ...

See original GitHub issue

Hi,

I am registering the component as per the docs and importing Vue as per my other components but getting the error "Error in created hook: “ReferenceError: Vue is not defined”.

Below is the complete .vue file.

Any help greatly appreciated.

Thanks.

<template>
  <div>
    <datatable :columns="columns" :data="rows"></datatable>
  </div>
</template>

<script>
import Vue from "vue"
import DatatableFactory from "vuejs-datatable"
Vue.use(DatatableFactory)

export default {
  data () {
    return {
      columns: [
        {label: "id", field: "id"},
        {label: "Username", field: "user.username"},
        {label: "First Name", field: "user.first_name"},
        {label: "Last Name", field: "user.last_name"},
        {label: "Email", field: "user.email"},
        {label: "address",
          representedAs: function (row) {
            return row.address + "<br />" + row.city + ", " + row.state
          },
          interpolate: true
        }
      ],
      rows: [
        {
          "id": 1,
          "user": {
            "username": "dprice0",
            "first_name": "Daniel",
            "last_name": "Price",
            "email": "dprice0@blogs.com"
          },
          "address": "3 Toban Park",
          "city": "Pocatello",
          "state": "Idaho"
        }
      ]
    }
  }
}
</script>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
pstephan1187commented, Sep 12, 2018

I found a way to fix the “Vue not defined” error without importing Vue and thus not bloating the ES5 distribution.

1reaction
robertjkcommented, Jun 20, 2018

@pstephan1187

Why would you require Vue object to be registered globally? That’s the opposite to the idea how isolated components work - they should declare all their dependencies internally. You could add @import Vue from 'vue'; in your component and the problem would be gone. It would make your component (library) easier to use - nobody would have to remember/read docs to know that to use it you have to have some global variables declared. It would also save people (like me) who try to write fully modular applications - without declaring any global variables - from polluting the code with some global variable only to use a single library.

It’s like old JQuery days, when to use a JQuery plugin, you’d have to have $/JQuery defined as a global variable. JavaScript has grown since then. So should we in how we build our tools.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue is not defined - javascript - Stack Overflow
I am trying to build a demo app with Vue.js. What I am getting is an odd error that ...
Read more >
Vue is not defined! $ is not defined! What am i doing wrong?
Chrome is giving an error Vue is not defined . I tried to use ellixir browserify with jquery just to test it out,...
Read more >
ReferenceError is not defined errors in production but works in ...
I made my first vue3 app, it is working in development but not in production (vite build). I've managed to re…
Read more >
3 Anti-Patterns to avoid in Vue.js - Binarcode
The shortest code is not always the best and "easy and fast" ways can often have disadvantages. Every programming language, project or framework...
Read more >
Property or Method is Not Defined - Michael Thiessen
Chances are if you've been developing with Vue for any amount of time, you've gotten this error: Most of the time this error...
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