From f354c9e1182bda969f811169494cd53a64b08a7a Mon Sep 17 00:00:00 2001 From: Sinclair Chen Date: Wed, 6 Jul 2022 15:50:31 -0700 Subject: [PATCH] fix extension import (backend) In firebase, typescript compiles imports into common js imports like `const StarterKit = require("@tiptap/starter-kit")` Even though StarterKit is exported from the cjs file, it gets imported as undefined. But it magically works if we import * If you're reading this in the future, consider replacing StarterKit with the entire list of extensions. --- common/package.json | 1 + common/util/parse.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/common/package.json b/common/package.json index c8115d84..5d17a4d2 100644 --- a/common/package.json +++ b/common/package.json @@ -8,6 +8,7 @@ }, "sideEffects": false, "dependencies": { + "@tiptap/starter-kit": "^2.0.0-beta.190", "lodash": "4.17.21" }, "devDependencies": { diff --git a/common/util/parse.ts b/common/util/parse.ts index fe629721..63da6fee 100644 --- a/common/util/parse.ts +++ b/common/util/parse.ts @@ -1,6 +1,6 @@ import { MAX_TAG_LENGTH } from '../contract' -import { generateText, JSONContent } from '@tiptap/core' -import StarterKit from '@tiptap/starter-kit' +import { generateText, JSONContent, Extension } from '@tiptap/core' +import * as StarterKit from '@tiptap/starter-kit' // needed for cjs import to work on firebase export function parseTags(text: string) { const regex = /(?:^|\s)(?:[#][a-z0-9_]+)/gi @@ -31,5 +31,7 @@ export function parseWordsAsTags(text: string) { } export function richTextToString(text: JSONContent | string) { - return typeof text === 'string' ? text : generateText(text, [StarterKit]) + return typeof text === 'string' + ? text + : generateText(text, [StarterKit as unknown as Extension]) }