
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThis is actually a Node.js module system issue, not specifically a Sanity problem, but I can help clarify what's happening here.
You're correct that Node.js supports dynamic import() in CommonJS files - but there's a critical detail: the file you're importing (../config.js) must be recognized as an ES module by Node.js.
The error message is telling you that config.js contains ES module syntax (export), but Node.js is trying to parse it as CommonJS because:
package.json doesn't have "type": "module", AND.mjs extensionSolutions:
Option 1: Make config.js recognizable as ESM
config.js to config.mjs, OR"type": "module" to your package.jsonOption 2: Keep everything CommonJS
If prebuild.js needs to stay as CommonJS (.js without "type": "module"), convert config.js to use CommonJS exports:
// config.js
const config = {
// your config
};
module.exports = { config };Then in prebuild.js:
// prebuild.js
(async function () {
const { createClient } = require("next-sanity");
const { config } = require("../config.js");
})();Option 3: Make prebuild.js an ES module
Rename to prebuild.mjs and use ESM throughout:
// prebuild.mjs
import { createClient } from "next-sanity";
import { config } from "../config.js";The Node.js docs are correct - dynamic import() works in CommonJS, but the target file still needs to be identifiable as an ES module through file extension or package.json configuration. Node.js can't determine module type purely from file contents when using .js extension without package.json hints.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store