remarkjs / remark

markdown processor powered by plugins part of the @unifiedjs collective
https://remark.js.org
MIT License
7.66k stars 358 forks source link

Error "document is not defined" when running in browser extension background #1165

Closed phuctm97 closed 1 year ago

phuctm97 commented 1 year ago

Initial checklist

Affected packages and versions

remark-stringify

Link to runnable example

No response

Steps to reproduce

Import remark-stringify into a browser extension's background service worker script. The script initialization will fail immediately with error "document is not defined".

I checked the code, it seems like there is a use of document.createElement("i"), I'm not sure what it's for.

Expected behavior

It should work fine in service worker environment and does not depend on DOM API.

Actual behavior

It depends on document and fails in non-DOM environment.

Runtime

Node v16

Package manager

yarn 1

OS

macOS

Build and bundle tools

esbuild

wooorm commented 1 year ago

You can configure your bundler. It only does this if you say it is running in a browser (browsers have a document), it doesn't do so in places that have no document (node, deno, worker, react-native).

If you run in a browser but without document, configure your tools: https://github.com/wooorm/parse-entities/issues/19

github-actions[bot] commented 1 year ago

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.