From d957c86a5b84baeaa2cf25daaed722ca7780d710 Mon Sep 17 00:00:00 2001 From: linonetwo Date: Tue, 6 Feb 2024 23:48:39 +0800 Subject: [PATCH] fix: error when tldraw require localStorage on RN --- src/tw-whiteboard/widget-loader.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tw-whiteboard/widget-loader.js b/src/tw-whiteboard/widget-loader.js index eaebd99..ad9ee37 100644 --- a/src/tw-whiteboard/widget-loader.js +++ b/src/tw-whiteboard/widget-loader.js @@ -5,9 +5,13 @@ return; } // separate the widget from the exports here, so we can skip the require of react code if `!$tw.browser`. Those ts code will error if loaded in the nodejs side. - const components = require('$:/plugins/linonetwo/tw-whiteboard/widget.js'); - const { whiteboard } = components; - /* eslint-disable @typescript-eslint/no-unsafe-member-access */ - exports.whiteboard = whiteboard; - exports['edit-whiteboard'] = whiteboard; + try { + const components = require('$:/plugins/linonetwo/tw-whiteboard/widget.js'); + const { whiteboard } = components; + /* eslint-disable @typescript-eslint/no-unsafe-member-access */ + exports.whiteboard = whiteboard; + exports['edit-whiteboard'] = whiteboard; + } catch (error) { + console.error('Error loading tw-whiteboard widget', error); + } })();