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.

[1.0.0-alpha.3] TypeError: Cannot read property 'jquery' of null

See original GitHub issue

I’m using MaterializeCSS + VueJS with Laravel Webpack.

Expected Behavior

Initializing the form when the component is loaded.

Current Behavior

[Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'jquery' of null"

2018-01-15 09-53-03 developer tools - http localhost 3000 sales-spec

Steps to Reproduce (for bugs)

//...
data() {
  return {
    modalId: 'modal-order'
  }
},
mounded() {
  this.init();
},
methods: {
  init() {
    let elem = document.querySelector(`#${this.modalId}`);
    this.instance = M.Modal.init(elem, {
        onOpenStart: () => {
            this.show();
        },
        onCloseEnd: () => {
            this.resetForm();
        }
    });
  }
}

Possible Solution

If you execute the code after jQuery is loaded, the error disappears:

//...
data() {
  return {
    modalId: 'modal-order'
  }
},
mounded() {
  this.init();
},
methods: {
  init() {
    $(document).ready(() => {
        let elem = document.querySelector(`#${this.modalId}`);
        this.instance = M.Modal.init(elem, {
            onOpenStart: () => {
                this.show();
            },
            onCloseEnd: () => {
                this.resetForm();
            }
        });
    });
  }
}

Your Environment

  • Version used: 1.0.0-alpha.3
  • Browser Name and version: All latest browsers (Google Chrome, Mozilla Firefox, Microsoft Edge, Opera)
  • Operating System and version (desktop or mobile): Windows 10 Pro desktop, Windows 7 desktop.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Dogfalocommented, Jan 16, 2018

Try using https://vuejs.org/v2/api/#ref instead of query selector in Vue

0reactions
andrey-helldarcommented, Jan 16, 2018

Hmm … I did not think about it, thanks 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'val' of null jquery
I'm trying to pass form values, check them and then return the response with jquery, everything gets passed correctly, the image gets ...
Read more >
Uncaught TypeError: Cannot read property of null - iDiallo
This will result in Uncaught TypeError: Cannot read property 'value' of null . The reason will be that the element with id input...
Read more >
cannot read properties of null (reading '0') react
Solution: The TypeError: Cannot read properties of null (reading 'data') occurs when your first render, your data with that id isn't mounted to...
Read more >
Cannot read property 'data' of null
Hey, I have this problem, but can`t resolve. Some can help me? Website: https://escolabrasileirademedicina.com.br. Uncaught TypeError: Cannot ...
Read more >
Uncaught TypeError: Cannot read property 'nTable' of null
Uncaught TypeError: Cannot read property 'nTable' of null ... dataTables.min.js:83) at Function.each (jquery-2.2.3.min.js:2) at ...
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