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

Studio won't start (Uncaught TypeError: Cannot read property 'sanity' of undefined) #2190

Closed
aaronadamsCA opened this issue Dec 14, 2020 · 21 comments

Comments

@aaronadamsCA
Copy link

aaronadamsCA commented Dec 14, 2020

I'm getting the following when trying to run the latest version of Sanity:

Uncaught error

Cannot read property 'sanity' of undefined

Stack:

TypeError: 
    at https://redacted.netlify.app/static/js/app.bundle.js?4c054893bbf7f9a02dc8:1262:130116
    at be (https://redacted.netlify.app/static/js/app.bundle.js?4c054893bbf7f9a02dc8:90:138488)
    at be (https://redacted.netlify.app/static/js/app.bundle.js?4c054893bbf7f9a02dc8:90:138261)
    at e.t.createStyles (https://redacted.netlify.app/static/js/app.bundle.js?4c054893bbf7f9a02dc8:90:144358)
    at e.t.renderStyles (https://redacted.netlify.app/static/js/app.bundle.js?4c054893bbf7f9a02dc8:90:144597)
    at u (https://redacted.netlify.app/static/js/app.bundle.js?4c054893bbf7f9a02dc8:90:145157)
    at https://redacted.netlify.app/static/js/app.bundle.js?4c054893bbf7f9a02dc8:90:144973
    at ro (https://redacted.netlify.app/static/js/vendor.bundle.js?3e9baa871d4a49047f70:22:83207)
    at lo (https://redacted.netlify.app/static/js/vendor.bundle.js?3e9baa871d4a49047f70:22:83310)
    at pu (https://redacted.netlify.app/static/js/vendor.bundle.js?3e9baa871d4a49047f70:22:101244)

(Your browsers Developer Tools may contain more info)

This is where the error is occurring:

const color = theme.sanity.color.base

I think the problem might be this downgrade from @sanity/ui@1.0.0-beta.14 to @sanity/ui@0.28.0:

https://github.com/sanity-io/sanity/pull/2183/files

Rolling back with npm i @sanity/base@2.0.9 @sanity/cli@2.0.9 @sanity/components@2.0.9 @sanity/core@2.0.9 @sanity/dashboard@2.0.9 @sanity/default-layout@2.0.9 @sanity/default-login@2.0.9 @sanity/desk-tool@2.0.9 @sanity/google-maps-input@2.0.9 @sanity/vision@2.0.9 resolves the issue.

Which versions of Sanity are you using?

  "dependencies": {
    "@sanity/base": "^2.1.2",
    "@sanity/cli": "^2.1.0",
    "@sanity/components": "^2.1.0",
    "@sanity/core": "^2.1.2",
    "@sanity/dashboard": "^2.1.0",
    "@sanity/default-layout": "^2.1.2",
    "@sanity/default-login": "^2.1.0",
    "@sanity/desk-tool": "^2.1.2",
    "@sanity/google-maps-input": "^2.1.2",
    "@sanity/vision": "^2.1.0"
  }

What operating system are you using?

Happens in Debian dev and Ubuntu build environments.

Which versions of Node.js / npm are you running?

6.14.8
v12.19.0
@nboliver
Copy link

Also experiencing the same issue.

@willTastyMakers
Copy link

willTastyMakers commented Dec 15, 2020

The same as well

Which versions of Sanity are you using?
TypeScript

"@sanity/base": "^2.1.1",
    "@sanity/cli": "^2.1.0",
    "@sanity/color-input": "^2.1.0",
    "@sanity/components": "^2.1.0",
    "@sanity/core": "^2.1.0",
    "@sanity/default-layout": "^2.1.1",
    "@sanity/default-login": "^2.1.0",
    "@sanity/desk-tool": "^2.1.1",
    "@sanity/form-builder": "^2.1.1",
    "@sanity/image-url": "^0.140.19",
    "@sanity/vision": "^2.1.0",
    
    ....
    "sanity-plugin-media": "^0.4.0",
    "sanity-plugin-seo-tools": "^1.0.6",
    "sanity-plugin-tabs": "^2.0.1",
    "sanity-typed-queries": "^0.7.3",

     ...
   
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-icons": "^4.1.0",

What operating system are you using?
macOS Catalina | 10.15.7
macOS Big Sur | 11.1

Which versions of Node.js / npm are you running?

node v12.16.2
npm 6.14.8

@bjoerge
Copy link
Member

bjoerge commented Dec 18, 2020

Are any of you having styled-components as a dependency in package.json by any chance? If you do, it might help upgrading it to version >= 5.2

@aaronadamsCA
Copy link
Author

Not in package.json, only in package-lock.json. There must be something about the dependency tree that changed.

Before:

$ npm ls styled-components
├─┬ @sanity/desk-tool@2.0.9
│ └─┬ @sanity/form-builder@2.0.9
│   └─┬ @sanity/portable-text-editor@0.1.22
│     └── styled-components@5.1.0  deduped
└─┬ sanity-plugin-content-model-graph@1.1.1
  └── styled-components@5.1.0

After:

$ npm ls styled-components
├─┬ UNMET PEER DEPENDENCY @sanity/base@2.1.3
│ └── UNMET PEER DEPENDENCY styled-components@5.2.1
├─┬ @sanity/desk-tool@2.1.3
│ └─┬ @sanity/form-builder@2.1.3
│   └─┬ @sanity/portable-text-editor@0.1.25
│     └── styled-components@5.1.0  deduped
└─┬ sanity-plugin-content-model-graph@1.1.1
  └── styled-components@5.1.0

npm ERR! peer dep missing: @sanity/base@^1.0.0, required by sanity-plugin-content-model-graph@1.1.1

That plugin did indeed "require" a peer dependency of v1, so I tried uninstalling it, but it made no difference; the same error occurs. New dependency tree:

$ npm ls styled-components
├─┬ @sanity/base@2.1.3
│ └── UNMET PEER DEPENDENCY styled-components@5.2.1 
└─┬ @sanity/desk-tool@2.1.3
  └─┬ @sanity/form-builder@2.1.3
    └─┬ @sanity/portable-text-editor@0.1.25
      └── styled-components@5.1.0 

npm ERR! peer dep missing: styled-components@^5.2, required by @sanity/ui@0.28.0

I'm sure installing styled-components 5.2 in my tree might resolve this, but give these dependencies are (now) all coming from official packages, I think there's an issue with your tree, not mine 🙂

@nboliver
Copy link

Anyone else using sanity-plugin-tabs?
Wondering if it may be incompatible with 2.1.x

@willTastyMakers
Copy link

willTastyMakers commented Dec 19, 2020

Yes I have been having problems with sanity-plugin-tabs as well. I have been trying to solicit help on sanity slack channel to no avail. Knut ( I believe he is in the leadership of Sanity.io) suspects that there may be an issue with sanity-plugin-tabs.

As to the actual problem described in this GH issue, I am not sure it has to do with sanity-plugin-tabs, since I was able to get everything compiling in my local studio yesterday with the latest Sanity Releases, including sanity-plugin-tabs. While I have been able to get everything running, I am still facing problems with other issues that I believe are related to Tabs. My experience thus far trying to develop with in the Sanity studio, has been very difficult. I have gone down many rabbit holes trying to figure out if a problem stems from a 3rd party plugin, outdated sanity version, or just some failure to understand how documents, objects, fields, and field-types relate to user input.

I am using Tabs to reveal fields from a shopify Product document. When the user enters text in the input field, a kind of processing delay occurs as the the entire Edit Pane of the studio begins to continually re-render with each input. It builds up until the user is unable to see the text they are entering for several seconds after entering it.

You can find my links on Slack to this issue here:
https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1608142988453800

Currently, I downloaded sanity-plugin-tabs as zip file from git hub and copied into my studio as an inputComponent. Downloading and including this way, I am hoping to continue to debugging. Hence, my other question about how documents are processed in the sanity studio.

https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1608246117141700

@israelroldan
Copy link
Contributor

We're experiencing the same issue and we're not using sanity-plugin-tabs so that theory goes out the window? 🤔

@willTastyMakers
Copy link

willTastyMakers commented Dec 21, 2020

@israelroldan is the "same issue" that you are referring too, the issue with the sanity studio crashing on instantiation or the issue of a delay in processing of text in an input field as the speed and volume of text increases?

@aaronadamsCA
Copy link
Author

Anyone else using sanity-plugin-tabs?
Wondering if it may be incompatible with 2.1.x

I am not using this plugin. My issue was with a different plugin.

I believe all plugins using Styled Components may be affected by this, because the current release of Sanity is requiring both versions 5.1 and 5.2 of Styled Components in its dependency tree.

@aaronadamsCA
Copy link
Author

Deleting my package-lock.json and reinstalling from the existing package.json successfully works around the issue.

However, this should not be necessary, and I still think there is a broken dependency chain in Sanity.

Specifically:

  • "@sanity/desk-tool": "^2.1.3" has dependency "@sanity/form-builder": "2.1.3"
  • "@sanity/form-builder": "2.1.3" has dependency "@sanity/ui": "^0.28.0"
  • "@sanity/ui": "^0.28.0" has peer dependency "styled-components": "^5.2"
  • "@sanity/form-builder": "2.1.3" is not currently meeting this peer dependency

If you meet the peer dependency, I believe you will solve the issue.

@fvieira
Copy link

fvieira commented Dec 29, 2020

I have no idea what causes it, but at least to me deleting node_modules and reruning yarn seems to fix it (did it on two different projects).

bjoerge added a commit that referenced this issue Jan 13, 2021
…d of direct dependencies

This should help address issues with multiple versions of both @sanity/ui  and styled-components (e.g. #2190).
@mariuslundgard
Copy link
Member

This should be fixed after the introduction of @sanity/ui v0.33.4.

@hdoro
Copy link
Contributor

hdoro commented Mar 9, 2021

For those still with the problem, I'm still facing this when using sanity-plugin-media with Sanity 2.6.0 and up. The plugin adds @sanity/ui: 0.33.4 as a fixed-version dependency, whereas the studio is requiring ^0.33.6. This double-version behavior seems to be what's causing the issue.

I'll notify the author about it :)

Note: this is probably because I'm using yarn workspaces, as the same studio was working fine before switching to it!

@jkananen
Copy link

jkananen commented Jun 9, 2021

To anyone else still being bothered with this, try using npm instead of yarn.

I've got one project where sanity-plugin-media works with yarn and another that refuses to work with yarn but works with npm. There are of course other differences in dependencies, but I'll take the quickest route now and switch to npm where it helps. Maybe there's time later to dig deeper.

@jkananen
Copy link

Sanity v2.11.0 resolved this for my envs.

@bhavinpatil
Copy link

TypeError: Cannot read properties of null (reading 'jsonType')
    at validateNonObjectFieldsProp (/static/js/app.bundle.js:169457:16)
    at _default (/static/js/app.bundle.js:169425:155)
    at visitors.reduce._objectSpread._problems (/static/js/app.bundle.js:167933:17)
    at Array.reduce ()
    at /static/js/app.bundle.js:167932:21
    at /static/js/app.bundle.js:167951:70
    at /static/js/app.bundle.js:168067:12
    at /static/js/app.bundle.js:168082:95
    at Array.forEach ()
    at traverseSchema (/static/js/app.bundle.js:168081:9)

go this error after using sanity start command for checking the schemas for my project, although it was not showing any error on command line but while visiting the localhost it was giving this error.

@cassette88
Copy link

TypeError: Cannot read properties of null (reading 'jsonType')

Found a potential cause of this issue on Sanity's slack (if anyone else has this problem) : an object in the schema was missing a type.

@chiragksharma
Copy link

TypeError: Cannot read properties of null (reading 'jsonType')

Found a potential cause of this issue on Sanity's slack (if anyone else has this problem) : an object in the schema was missing a type.

Thanks. it works now

@akshit2649
Copy link

TypeError: Cannot read properties of null (reading 'jsonType')

Found a potential cause of this issue on Sanity's slack (if anyone else has this problem) : an object in the schema was missing a type.

Thanks. it works now

Can you explain please? I am getting this error and cannot find a solution.

@DID0101
Copy link

DID0101 commented Dec 6, 2022

TypeError: Cannot read properties of null (reading 'jsonType')

Found a potential cause of this issue on Sanity's slack (if anyone else has this problem) : an object in the schema was missing a type.

Thanks. it works now

how did you fix it

@tonybanks90
Copy link

I faced the same error and solve it by installing the canary version of next 13 "npm i next@13.0.8-canary.2"

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

No branches or pull requests