Hey guys im trying to deploy my project.
I run Vercel Build through my terminal it comes back with no errors but when run vercel deploy I keep getting
Build Failed Command "npm run build" exited with 1
Any suggestions or fixes would be greatly apreciated! I see it says I need a projectId but my .env.local contains my id
NEXT_PUBLIC_SANITY_DATASET=production
NEXT_PUBLIC_SANITY_PROJECT_ID=8a64h111
NEXT_PUBLIC_BASE_URL=http://localhost:3000/````
I'm really stumped here.
```23:27:55.917 | Error: Configuration must contain `projectId`
23:27:55.917 | at exports.initConfig (/vercel/path0/node_modules/@sanity/client/lib/config.js:42:11)
23:27:55.918 | at SanityClient.config (/vercel/path0/node_modules/@sanity/client/lib/sanityClient.js:89:25)
23:27:55.918 | at new SanityClient (/vercel/path0/node_modules/@sanity/client/lib/sanityClient.js:53:8)
23:27:55.918 | at SanityClient (/vercel/path0/node_modules/@sanity/client/lib/sanityClient.js:50:12)
23:27:55.918 | at exports.createClient (/vercel/path0/node_modules/next-sanity/dist/next-sanity.cjs.production.min.js:1:1023)
23:27:55.918 | at Object.5149 (/vercel/path0/.next/server/pages/index.js:1055:75)
23:27:55.919 | at __webpack_require__ (/vercel/path0/.next/server/webpack-runtime.js:25:42)
23:27:55.919 | at /vercel/path0/.next/server/pages/index.js:20:65
23:27:55.919 | at Function.__webpack_require__.a (/vercel/path0/.next/server/webpack-runtime.js:89:13)
23:27:55.919 | at Object.2265 (/vercel/path0/.next/server/pages/index.js:11:21)
23:27:55.920 |
23:27:55.920 | > Build error occurred
23:27:55.922 | Error: Failed to collect page data for /
23:27:55.922 | at /vercel/path0/node_modules/next/dist/build/utils.js:916:15 {
23:27:55.922 | type: 'Error'
23:27:55.923 | }
23:27:55.978 | Error: Command "npm run build" exited with 1```
CodePudding user response:
```23:27:55.917 | Error: Configuration must contain
projectId
It looks like you didn't add the environment variable "projectId" on Varcel. Here's how to do it.. If you added it, check if you have a typo there.
CodePudding user response:
You need to provide more information in addition to the stack trace but assuming all libraries are working correctly...
Most libraries don't read from .env.local
or process.env
by default. You first use another library like dotenv-flow to load .env.local
into process.env
, then pass a configuration (usually an object) to the library's constructor.
Line 20, column 65 of pages/index.js
(assuming you are not compiling from typescript) may look something like this: createClient()
you want it to look like this: createClient({projectId: process.env.projectId})