Sanity 3.4.0 RxJS import error: "No matching export for import 'tap'

16 replies
Last updated: Feb 21, 2023
I have updated to sanity 3.4.0 and now I am getting this error along with 2 other errors that are very similar.
[ERROR] No matching export in "node_modules/rxjs/_esm5/index.js" for import "tap"

node_modules/@sanity/portable-text-editor/lib/index.esm.js
:5:16: 5 │ import { defer, tap, switchMap, of, EMPTY, concatMap, Subject } from 'rxjs';
AI Update

This is a known dependency conflict issue that occurred with Sanity 3.4.0 related to how RxJS operators are imported in the @sanity/portable-text-editor package. The error happens because the package is trying to import tap, switchMap, and concatMap from the main rxjs module, but your build tool can't find these exports in the ESM5 build.

First, try the standard dependency resolution fix:

Delete your lock file and node_modules, then reinstall:

rm -rf node_modules package-lock.json  # or yarn.lock if using yarn
npm install

If that doesn't work:

Based on community discussion, you can temporarily fix this by manually editing node_modules/@sanity/portable-text-editor/lib/index.esm.js and changing the import from:

import { defer, tap, switchMap, of, EMPTY, concatMap, Subject } from 'rxjs';

to:

import { defer, of, EMPTY, Subject } from 'rxjs';
import { tap, switchMap, concatMap } from 'rxjs/operators';

However, this is just a temporary workaround since it'll be overwritten on the next install.

The recommended long-term solution:

The v2 to v3 upgrade path had several dependency issues like this. If you continue having problems, the community consensus is to start fresh with a new Sanity v3 project and migrate your:

  • Schema definitions
  • Configuration files
  • Custom components and plugins

This avoids the dependency conflicts that can occur with upgraded projects.

Bonus tip: While you're working on your schemas, consider adopting the new defineField and defineType helper functions - they provide better TypeScript support and validation errors:

import {defineField, defineType} from "sanity"

The root cause is how the portable text editor's dependencies were bundled in that version, and a clean dependency tree (either through fresh install or new project) typically resolves it.

Show original thread
16 replies
sounds like a conflict in your dep lock file. delete it and node_modules and run install again.
I tried that and it didn't work. I was able to fix it by changing the import in the node_modules/@sanity/portable-text-editor from rxjs to rxjs/operators for tap, switchMap, and concatMap. Not sure why that isn't changed with an update, im sure if I built it as a new project it would probably work.
def. I found that the sanity upgrade story from v2 to v3 had A LOT of issues. its probably better to install from scratch and move your config, schema, components over.
Yea i'm thinking about doing that as well. I just deployed it and now I'm having reference issues.
I'm getting this but I didn't change anything in my schemas
what does your schema look like for this list.
{
name: 'subCategories',
type: 'array',
title: 'List of sub categories',
of: [
{
name: 'subCategory',
type: 'reference',
title: 'Sub Category',
to: [{type: 'subCategories'}],
},
],
},
do you mean to pass
type: subCategory
instead of a reference to itself?
No the
name
of the subCategory document is subCategories so that is correct. I haven't changed anything and it was working before. The only thing I did different was I pulled the repo from github to another computer and deployed from the other computer, but I didn't make any changes to the the schemas.
I'm thinking it has something to do with that
right but the name of the field you are making also has the same name. I can imagine its doing a circular look because the names are the same.
defineField({
      title: "Sub Categories",
      name: "subCategories", // either change this 
      type: "array",
      of: [
        {
          type: "reference",
          to: {type: "subCategories"}, // or change this 
        },
      ],
    }),
This would be invalid anyway so thats prolly why its failing now as its more strict or has better validation.
you should use the new defineField and defineType functions too. it will give you validation errors when working with the schema.
import {defineField, defineType} _from_ "sanity"
Sorry to take you down this path man. I found the problem. I pushed an old file to github and messed everything up. The suggestions from defineField was a good one though and I will update my code to use this. Thanks

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?