Where to place translation script file in Sanity project structure?
The issue you're hitting is that this gist was written for Sanity v2 and uses the old part:@sanity/base/client import system, which only worked inside the Studio's build context. That syntax doesn't work in modern Sanity v3+ projects or as a standalone Node.js script.
For Sanity v3 (Current Version)
Replace the old import with the modern client setup. Create your script (e.g., scripts/translate.js) like this:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
token: 'your-token-with-write-access',
apiVersion: '2024-01-01',
useCdn: false
})
// ... rest of the translation script code from the gistSteps to make it work:
- Install the client:
npm install @sanity/client - Get a token from your Sanity project dashboard with write permissions
- Add
"type": "module"to yourpackage.jsonto use ES modules, OR convert all imports to CommonJSrequire()syntax - Run with:
node scripts/translate.js
If You're Still on Sanity v2
The part: system only works inside the Studio's execution context. Place the script in scripts/translate.js and run:
sanity exec scripts/translate.js --with-user-tokenThe --with-user-token flag gives your script access to the Studio's parts system and authenticated client.
Modern Alternative: Sanity Functions
For ongoing translation needs (not just one-time migrations), consider using Sanity Functions which give you serverless compute with built-in client access. But for a migration script like this, the standalone approach above is simpler.
The key takeaway: part:@sanity/base/client was v2-specific Studio magic that's been replaced by the standard @sanity/client package you can use anywhere.
Show original thread7 replies
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.