Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Error with Sanity configuration and environment variables

11 replies
Last updated: Aug 31, 2022
Error: Configuration must contain `projectId`
    at exports.initConfig (/studio/static/js/app.bundle.js:188293:11)
    at SanityClient.config (/studio/static/js/app.bundle.js:183556:25)
    at new SanityClient (/studio/static/js/app.bundle.js:183524:8)
    at SanityClient (/studio/static/js/app.bundle.js:183521:12)
    at createClient (/studio/static/js/app.bundle.js:183266:64)
    at Object. (/studio/static/js/app.bundle.js:183216:43)
    at __webpack_require__ (/studio/static/js/vendor.bundle.js:713:30)
    at fn (/studio/static/js/vendor.bundle.js:118:20)
    at Object. (/studio/static/js/app.bundle.js:183064:39)
    at __webpack_require__ (/studio/static/js/vendor.bundle.js:713:30)
Getting this error out in my development instance of sanity. I’m loading an
.env.development
file into sanity to define projectId and dataset which looks like this:

# For Next
NEXT_PUBLIC_SANITY_PROJECT_ID="#######"
NEXT_PUBLIC_SANITY_DATASET="production"

# For Studio
SANITY_STUDIO_API_PROJECT_ID="#######"
SANITY_STUDIO_API_DATASET="production"
Aug 31, 2022, 3:48 PM
Do you pass that variable to your client?
Aug 31, 2022, 3:51 PM
Can you post the snippet where these variables are consumed?
Aug 31, 2022, 3:51 PM
This is my
sanity.json

{
  "root": true,
  "api": {
    "projectId": "######",
    "dataset": "production"
  },
  "project": {
    "name": "Sanity Studio",
    "basePath": "/studio"
  },
  "plugins": [
    "@sanity/base",
    "@sanity/components",
    "@sanity/default-layout",
    "@sanity/default-login",
    "@sanity/desk-tool"
  ],
  "env": {
    "development": {
      "plugins": [
        "@sanity/vision"
      ]
    }
  },
  "parts": [
    {
      "name": "part:@sanity/base/schema",
      "path": "./schemas/schema"
    }
  ]
}
Aug 31, 2022, 3:52 PM
You don’t have to hide your project ID, it’s not sensitive. 🙂
Aug 31, 2022, 3:52 PM
Is this a new project or did an existing project break?
Aug 31, 2022, 3:53 PM
i read somewhere that if you include
.env.development
in your
/studio
directory sanity will incorporate those values, but now even just setting it in my
sanity.json
file it’s not woring
Aug 31, 2022, 3:53 PM
it’s basically a new project — running the next.js starter blog repo
Aug 31, 2022, 3:54 PM
what i’ve attempted so far to fix this:
removed
.env.development
set projectId manually
build sanity
rebuilt sanity

still getting the error
🤔
Aug 31, 2022, 3:57 PM
also wondering if my production build errors might have something to do with it:

...
[4/4] Building fresh packages...
$ lerna bootstrap
lerna notice cli v4.0.0
lerna info ci enabled
lerna info Bootstrapping 1 package
lerna info Installing external dependencies
lerna ERR! npm ci exited 1 in 'queer-thoughts-sanity'
lerna ERR! npm ci stderr:
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR! 
npm ERR! Missing: react-icons@4.4.0 from lock file
npm ERR! Missing: sass@1.54.7 from lock file
npm ERR! Missing: immutable@4.1.0 from lock file
npm ERR! 
npm ERR! A complete log of this run can be found in:
npm ERR!     /vercel/.npm/_logs/2022-08-31T15_59_10_014Z-debug-0.log
lerna ERR! npm ci exited 1 in 'queer-thoughts-sanity'
error Command failed with exit code 1.
info Visit <https://yarnpkg.com/en/docs/cli/install> for documentation about this command.
Error! Command "yarn install" exited with 1
...
Aug 31, 2022, 4:01 PM
decided to just re-clone this and copy my code over and it seems to be working 🙂
Aug 31, 2022, 4:39 PM
Great! Thanks for following up. 😀
Aug 31, 2022, 4:43 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?