Skip to content

Commit

Permalink
docs: about ReferenceError: Element is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Mar 28, 2024
1 parent 5b8e6ed commit 815e24c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/doc/tutorials/en/012-About debugging.tid
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ tags: $:/tags/test-spec
The `$:/tags/test-spec` tag will mark this tiddler as a test and will be executed when you run `pnpm run test`.

Note that writing tests in the `wiki/tiddlers/tests` folder can only be done with JS; writing tests in plugins can be done with TS, but the tests will be packaged into the plugin, increasing its size.

!! Frequently Asked Questions

!!! Error at startup `ReferenceError: Element is not defined`

This is because one of the libraries you are using only supports browser-side rendering, and you need to make sure that the logic that uses it only runs on the browser side.

You can refer to the whiteboard plugin for this:

# Change the type of the Widget to `module-type: library` [[source|https://github.com/tiddly-gittly/tiddlywiki-whiteboard/blob/master/src/tw-whiteboard/widget.ts.meta]]
# Write a loader of type Widget `module-type: widget` that loads the plugin when it determines that it's a browser environment [[source|https://github.com/tiddly-gittly/tiddlywiki-whiteboard/blob/master/src/tw-whiteboard/widget-loader.js]]
11 changes: 11 additions & 0 deletions src/doc/tutorials/zh/012-关于调试.tid
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ tags: $:/tags/test-spec
`$:/tags/test-spec` 标签会将这个条目标记为测试,并在你执行 `pnpm run test` 的时候被执行。

注意在 `wiki/tiddlers/tests` 文件夹里写测试只能用 JS;在插件里写测试可以用 TS 但是测试会被打包进插件,增大插件体积。

!! 常见问题

!!! 启动时报错 `ReferenceError: Element is not defined`

这是因为你使用的某个库只支持浏览器端渲染,你需要确保使用它的逻辑只在浏览器端运行。

可以参考白板插件的做法:

# 将微件的类型改成 `module-type: library` [[源码|https://github.com/tiddly-gittly/tiddlywiki-whiteboard/blob/master/src/tw-whiteboard/widget.ts.meta]]
# 写一个加载器,类型是微件 `module-type: widget`,在判断是浏览器环境时再加载插件 [[源码|https://github.com/tiddly-gittly/tiddlywiki-whiteboard/blob/master/src/tw-whiteboard/widget-loader.js]]

0 comments on commit 815e24c

Please sign in to comment.