Skip to content

Error: sanity.cli.ts does not contain a project identifier #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gislitg opened this issue Dec 15, 2023 · 5 comments
Open

Error: sanity.cli.ts does not contain a project identifier #22

gislitg opened this issue Dec 15, 2023 · 5 comments

Comments

@gislitg
Copy link

gislitg commented Dec 15, 2023

I am getting the error: "Error: sanity.cli.ts does not contain a project identifier ("api.projectId"), which is required for the Sanity CLI to communicate with the Sanity API"

To Reproduce

Steps to reproduce the behavior:

  1. Use the export/backup example code but use the latest version 0.7-alpha
  2. Used a read+write token since I was also going to use the sanity dataset import but never got to that point
  3. Received error

Expected behavior

The workflow should succeed

Screenshots

Screenshot 2023-12-15 at 09 03 57

Which versions of Sanity are you using?
v3.21.3

@WahidN
Copy link

WahidN commented Mar 25, 2024

I think this is an issue with the latest sanity cli because when you use a js file instead of ts then it does work

@maxijonson
Copy link

In my case (and probably most of you too if you've followed Sanity's setup for NextJS), the issue is that I read these variables from the environment.

import { defineCliConfig } from "sanity/cli";

const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID;
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET;

export default defineCliConfig({
  api: { projectId, dataset },
});

Providing those in the env of the workflow step fixed this specific issue.

- name: Export Dataset
  uses: sanity-io/[email protected]
  with:
    args: dataset export [DATASET] [UPLOAD_FILE_PATH]
  env:
    SANITY_AUTH_TOKEN: [TOKEN]
    NEXT_PUBLIC_SANITY_PROJECT_ID: [PROJECT_ID]
    NEXT_PUBLIC_SANITY_DATASET: [DATASET]

Alternatively, you could also have a step that deletes the file and rewrites it with the values populated:

- run: |
    rm sanity.cli.ts && echo 'export default { api: { projectId: "PROJECT_ID", dataset: "DATASET" } }' > sanity.cli.ts

However, I then got a new error, which has been reported here: #23 . The workaround suggested by this comment fixed the new error. This was my final configuration to make it work with the latest CLI (3.43.0):

- name: Export dataset
  run: npx sanity dataset export ${{ inputs.dataset || 'production' }} ${{ steps.upload_name.outputs.UPLOAD_NAME }}
  env:
    SANITY_AUTH_TOKEN: ${{ secrets.SANITY_TOKEN }}
    NEXT_PUBLIC_SANITY_PROJECT_ID: ${{ secrets.SANITY_PROJECT_ID }}
    NEXT_PUBLIC_SANITY_DATASET: ${{ inputs.dataset || 'production' }}

@backflip
Copy link

I have the same issue and it seems to be connected to Node.js require(esm). It happens on Node.js 20.19 while Node.js 20.18 still works. And it works in newer Node.js versions when running the deploy sccript with NODE_OPTIONS=--no-experimental-require-module.

@jamesryan-dev
Copy link

also getting this on a project I recently updated from v1 to v3..

@dburles
Copy link

dburles commented Apr 6, 2025

Not the exact issue but closely related. It's not working on Node 23 while < 23 works fine.

"The requested module 'sanity/cli' does not provide an export named 'defineCliConfig'"

The default export lib/cli.js is incompatible with Node 23 because it's now treating it as ESM if your project package.json type = "module".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants