πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Error deploying GraphQL in Sanity due to prism syntax highlighter using document in node.js context

14 replies
Last updated: Feb 5, 2021
Anyone ever run into this one?
Uncaught [ReferenceError: document is not defined]
when deploying the graphql? It errors midway but still successfully deploys πŸ€” (Just ran a sanity upgrade just in case, but still persists!)
Anyone ever run into this one?  `Uncaught [ReferenceError: document is not defined]`
yarn deploy:graphql
yarn run v1.22.10
$ sanity graphql deploy --playground
Dataset: production
Tag: default

βœ” Checking for deployed API
βœ” Generating GraphQL schema
β ‹ Validating GraphQL APIError: Uncaught [ReferenceError: document is not defined]
–––––[FULL ERROR IN THREAD]–––––
βœ” Validating GraphQL API
βœ” Deploying GraphQL API
GraphQL API deployed to:
[myGraphQlPlaygroundUrlHere]
Jan 31, 2021, 4:14 PM
  Uncaught [ReferenceError: document is not defined] at reportException (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
    at innerInvokeEventListeners (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:312:9)
    at invokeEventListeners (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:251:3)
    at DocumentImpl._dispatch (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:205:11)
    at DocumentImpl.dispatchEvent (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
    at dispatchEvent (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:488:13)
    at /Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:493:11
    at new Promise (<anonymous>)
    at onDOMContentLoad (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:491:14)
    at Object.check (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/browser/resources/resource-queue.js:76:23) ReferenceError: document is not defined
    at Object.highlightAll (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/prismjs/components/prism-core.js:530:23)
    at Document.highlightAutomaticallyCallback (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/prismjs/components/prism-core.js:1193:5)
    at innerInvokeEventListeners (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:296:27)
    at invokeEventListeners (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:251:3)
    at DocumentImpl._dispatch (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:205:11)
    at DocumentImpl.dispatchEvent (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
    at dispatchEvent (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:488:13)
    at /Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:493:11
    at new Promise (<anonymous>)
    at onDOMContentLoad (/Users/r.derolez/code/helloastro/helloastro-cms/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:491:14)
Jan 31, 2021, 4:15 PM
I've been getting this constantly ever since upgrading sanity this week. After incrementally adding bits to a brand new empty studio I found mine throwing this error when I included a few specific plugins.
The plugins themselves were still working and the gql redeployed correctly.

I upgraded an old build and started getting the same error. Very odd
Jan 31, 2021, 6:37 PM
Do you have any syntax highlighting plugin or code preview/input installed in your studio? It seems to be stemming from prism (a syntax highlighter) using
document
in a node.js context.
Jan 31, 2021, 9:48 PM
Espen Hovlandsdal
the only thing I've got installed is the sanity color input!
Feb 1, 2021, 12:14 PM
Hm, looks like we’ve got a common denominator then!
Feb 1, 2021, 10:37 PM
Rafael Derolez
Are you also using the "color-list" plugin, or a different one? There's several color plugins out there
Feb 1, 2021, 11:10 PM
I’ve got the same problem, and the same plugin.
Feb 2, 2021, 4:15 AM
That's good to know. I'll have a look and see if I can find the culprit πŸ•΅οΈβ€β™‚οΈ πŸ”
Feb 2, 2021, 4:20 AM
Found the culprit - https://github.com/sanity-io/sanity/pull/2279 Hoping to have a fix in a day or two
πŸ™‚
Feb 2, 2021, 5:49 AM
Espen Hovlandsdal
no I'm using
"@sanity/color-input": "^2.1.4",
actually
Feb 2, 2021, 8:30 AM
Awesome to see it fixed so quickly though, nice work ✌️
Feb 2, 2021, 8:31 AM
Fixed in v2.3.3
Feb 4, 2021, 5:52 PM
🀘
Feb 4, 2021, 5:53 PM
Nice one thanks
Espen Hovlandsdal
Feb 5, 2021, 10:04 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?