tscanlin / tocbot

Build a table of contents from headings in an HTML document.
MIT License
1.39k stars 115 forks source link

A problem occurred while using typescript #290

Closed greenfivebird closed 1 year ago

greenfivebird commented 1 year ago

I according to the guide for the import

import * as tocbot from 'tocbot';

but the page hint me error TypeError: Cannot set properties of undefined (setting 'tocbot') I don't know how to resolve this problem

greenfivebird commented 1 year ago

if use vue3+ts , we should take out 'this'

typeof global !== 'undefined' ? global : this.window || this.global

to

typeof global !== 'undefined' ? global : window || global
tim-scanlin-ck commented 1 year ago

why does this cause issues for it?

greenfivebird commented 1 year ago

why does this cause issues for it?

Maybe Vue3 problem

yannji commented 1 year ago

I according to the guide for the import

import * as tocbot from 'tocbot';

but the page hint me error TypeError: Cannot set properties of undefined (setting 'tocbot') I don't know how to resolve this problem

I had the same problem you had today🙄

tscanlin commented 1 year ago

What if we just remove ‘this.’ So it directly references window / global?

tscanlin commented 1 year ago

Sorry I missed that you updated your previous comment. Here is a PR to address this: https://github.com/tscanlin/tocbot/pull/292

tscanlin commented 1 year ago

This prerelease has the fix, can one of you help verify it? tocbot@4.18.3-0

greenfivebird commented 1 year ago

This prerelease has the fix, can one of you help verify it? tocbot@4.18.3-0 yes ,I verify it, it can be used normally now

tscanlin commented 1 year ago

Thanks for verifying @greenfivebird! The fix is merged and published in tocbot@4.19.0