Error importing data into Sanity project due to outdated CLI version
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 productionReplace 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 yourProjectIdThe 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!
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.