Error importing data into Sanity project due to outdated CLI version

7 replies
Last updated: Jun 23, 2023
I'm in the process of merging two sanity projects together. I've moved the schemas and components ++ into a new project, and it is working fine. Now I want to migrate the data from the old projects into the new one. I managed to export it into a .ndjson file according to this documentation , now I try to follow the import steps found here , but I get the following error when I try:
Error: Command "dataset" is not available outside of a Sanity project context.
Run the command again within a Sanity project directory, where "@sanity/core"
is installed as a dependency.
As far as I can understand @sanity/core is a v2 package, right? Is there another way to do imports in v3?
AI Update

Good news! The sanity dataset import command absolutely works in Sanity v3. The error you're seeing is just about where you're running the command, not a version compatibility issue.

In Sanity v3, there's no separate @sanity/cli package anymore - the CLI is now part of the main sanity package. The dataset command needs to be run from within your Sanity project directory (where you have sanity installed as a dependency and your sanity.config.ts or sanity.config.js file exists).

Here's how to fix your issue:

Make sure you're in your new project directory where you've already moved your schemas. Navigate to the root of your Sanity project (the folder containing your sanity.config.ts file and package.json with sanity as a dependency).

Then run the import command from there:

sanity dataset import path/to/your-export.ndjson production

Replace production with whatever dataset name you want to import into.

If you need to specify a different project (maybe you're importing from one project to another), you can use the --project flag:

sanity dataset import your-export.ndjson production --project yourProjectId

The Sanity CLI works the same way in v3 - you just need to make sure you're running commands from within a properly initialized Sanity project directory where the sanity package is installed.

If you're still getting errors after confirming you're in the right directory, double-check that you have sanity installed in your project's package.json dependencies (not @sanity/cli - that's the old v2 package). You might need to run npm install if you haven't done so yet in your new project.

Also worth noting: when you import, the data will merge with any existing content in the target dataset. If you want a clean slate, you might want to create a fresh dataset first. And as a best practice, always export your target dataset before importing, just in case you need to roll back!

Has anyone done anything similar and can point me in the right direction?
If it’s a v3 project make sure you have a
sanity.cli.json
file
Do you mean sanity.cli.js / sanity.cli.ts?
Ah yes, sorry. Sounds like you might already have it?
I do, so I don't think that's the problem. But thanks for trying
It looks like you have V2 of the CLI installed.
Thank you! That was the issue. I updated the client and was able to import the dataset 😊

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?