Skip to content

Conversation

@yoshi389111
Copy link

Hello.

I've found what appears to be a small bug, so I'd like to report it.

Problem

In textlint/editor, if a named entity reference (e.g. >) is entered, the error "document is not defined" occurs.

Numeric entity references, however, work fine.

Screen Shot:

image

Error message and Stacktrace:

Failed to parse text by plugin: @textlint/markdown
Please report this error with the content to plugin author.
ReferenceError: document is not defined
 at e.exports [as default] (https://textlint-editor.netlify.app/textlint-worker.js:34:60556)
 at f (https://textlint-editor.netlify.app/textlint-worker.js:34:20587)
 at A (https://textlint-editor.netlify.app/textlint-worker.js:66:49848)
 at D (https://textlint-editor.netlify.app/textlint-worker.js:66:49790)
 at Object.write (https://textlint-editor.netlify.app/textlint-worker.js:66:49398)
 at o (https://textlint-editor.netlify.app/textlint-worker.js:14:26192)
 at e.exports (https://textlint-editor.netlify.app/textlint-worker.js:14:27118)
 at e.exports (https://textlint-editor.netlify.app/textlint-worker.js:26:328)
 at e.exports (https://textlint-editor.netlify.app/textlint-worker.js:66:11445)
 at Parser (https://textlint-editor.netlify.app/textlint-worker.js:34:84643)

Source:

image

This error seems to originate from parse-entities.
The latest version of parse-entities is 4.0.2, but textlint/editor currently uses 2.0.0, which appears to switch between the browser and non-browser versions.

textlint/editor imports the browser version of parse-entities, which depends on document. However, since textlint/editor runs the relevant code inside a Web Worker, document is not available, leading to the error.

Proposed Solution

Possible solutions could include:

  • Use the non-browser version of parse-entities
  • Upgrading to a newer version of parse-entities
  • Switching to a different library

For this pull request, I modified src/compiler.ts in @textlint/script-compiler to use the non-browser version, and added a Webpack plugin configuration.

With this change, we confirmed that the error no longer occurs when entering named entity references.
That said, we haven’t yet conducted extensive testing.

Copilot AI review requested due to automatic review settings August 25, 2025 14:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@azu
Copy link
Member

azu commented Aug 25, 2025

This issue related with
wooorm/parse-entities#19

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

Successfully merging this pull request may close these issues.

2 participants