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

(node:41536) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token: name (tocbot) #90

Closed
vimcaw opened this issue Mar 2, 2018 · 4 comments

Comments

@vimcaw
Copy link
Contributor

vimcaw commented Mar 2, 2018

I use npm to install tocbot, import it and init it.
I don't use the tool like webpack or gulp.

import tocbot from 'tocbot'

tocbot.init({
    // Where to render the table of contents.
    tocSelector: '.sidebar',
    // Where to grab the headings to build the table of contents.
    contentSelector: 'article',
    // Which headings to grab inside of the contentSelector element.
    headingSelector: 'h1, h2, h3',
    onClick: function () {
        if (shade.style.display === 'block') {
            switchSidebar();
        }
    }
});

But when I run, console display:

(node:41536) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token: name (tocbot)
@tscanlin
Copy link
Owner

tscanlin commented Mar 2, 2018

Can you link me to an example? Maybe its not being imported properly?

@vimcaw
Copy link
Contributor Author

vimcaw commented Mar 2, 2018

This project is powered by hexo, and this error doesn't recurrent in another environment.
Maybe I wrongly use it.
Must it need the tool like webpack or gulp?

@tscanlin
Copy link
Owner

tscanlin commented Mar 2, 2018

I believe hexo on its own doesn’t handle bundling frontend assets as it’s a tool to generate static sites.

So your options are: add webpack to hexo to support bundling / importing assets. Use something like gatsby which does use webpack, or just include the script on the page like so:

<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.1.1/tocbot.min.js"></script>

Hope that helps!

@vimcaw
Copy link
Contributor Author

vimcaw commented Mar 3, 2018

You are right, thanks.

@vimcaw vimcaw closed this as completed Mar 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants