Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
phuctm97 opened this issue May 18, 2023 · 2 comments
Closed
4 tasks done
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@phuctm97
Copy link

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

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels May 18, 2023
@wooorm
Copy link
Member

wooorm commented May 18, 2023

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: wooorm/parse-entities#19

@wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale May 18, 2023
@github-actions

This comment has been minimized.

@wooorm wooorm added the 🙋 no/question This does not need any changes label May 18, 2023
@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants