github-stats icon indicating copy to clipboard operation
github-stats copied to clipboard

Cannot read property 'appendChild' of null

Open YatinGupta777 opened this issue 7 years ago • 7 comments

index.js:54 Uncaught (in promise) TypeError: Cannot read property 'appendChild' of null
    at index.js:54

When i tried to plug it in this error showed up. Can you look into it ? thank you!

YatinGupta777 avatar Sep 29 '18 12:09 YatinGupta777

@YatinGupta777 Please double check lines similar to line 63 & 73 in your initialization code snippet and make sure you have valid CSS selector ( where you want the statistics to show up ) inside querySelector.

https://github.com/byliuyang/github-stats/blob/193e4fd0b4197dc880e9573259882777c9d15ed9/examples/example.html#L62-L74

magicoder10 avatar Sep 29 '18 17:09 magicoder10

I have used the exact same javascript code as yours changing the username,commits container and language container These are the CSS selector i used

  <div id="githubCommits">
  </div>
  <div id="githubLanguages">
  </div>

variables

const GITHUB_USERNAME = 'YatinGupta777'; 
const COMMITS_CONTAINER = '#githubCommits'; 
const LANGUAGES_CONTAINER = '#githubLanguages';

YatinGupta777 avatar Sep 30 '18 16:09 YatinGupta777

@YatinGupta777 Hope I fixed the bug in the most recent release. I also updated the example code here: https://github.com/byliuyang/github-stats/blob/9bcb2519b77a04a6c326c78728eac6ce0b8a2cbd/examples/example.html#L6

https://github.com/byliuyang/github-stats/blob/9bcb2519b77a04a6c326c78728eac6ce0b8a2cbd/examples/example.html#L22-L70

If you get error, please try clear the cache in developer console: screen shot 2018-09-30 at 3 59 06 pm

If this didn't resolve your issue, please let me know. For the next release, I am planing to support versioned cache.

magicoder10 avatar Sep 30 '18 23:09 magicoder10

Works great ! Thank you for creating this

YatinGupta777 avatar Oct 01 '18 11:10 YatinGupta777

Still happen randomly... it have to do with the cache, i am investigating this (weird because i did not had that issue before)

intika avatar Mar 20 '19 12:03 intika

Disabling the cache solve the issue i will check that out later on but clearly it's not solved... it worked for me for 3 days while i am developing https://starhub.be (by the way thank you for your tool, i did integrate it on my app) but suddenly it started giving that error randomly...

any way a quick-fix awaiting final fix

    function getCache(key) {
        //return localStorage.getItem(`github-stats-${key}`);
        return null;
    }

    function saveCache(key, value) {
        //localStorage.setItem(`github-stats-${key}`, value);
    }

    function getJSONCache(key) {
        //let value = getCache(key);
        //return value ? JSON.parse(value) : null;
        return null;
    }

    function saveJSONCache(key, value) {
        //saveCache(key, JSON.stringify(value));
    }

intika avatar Mar 20 '19 12:03 intika

@intika Thank you for submitting the issue. I'll investigate when I have time.

magicoder10 avatar Mar 21 '19 06:03 magicoder10