SimeonGriggs / sanity-remix-template

Sanity Studio v3 embedded into a Remix Vite application configured for Vercel hosting with visual editing
https://sanity-remix-template.sanity.build
164 stars 35 forks source link

Error: cloning the repo and using sanity deploy #64

Open trulymittal opened 7 months ago

trulymittal commented 7 months ago

Simply cloning the clean repo and trying to build by doing npx sanity build or sanity build, OR trying to deploy the sanity studio by doing npx sanity deploy or sanity deploy, it fails with vite errors... I dunno where and what I am getting wrong at, I have tried cloning multiple times but everytime the same issue, pnpm/bun both fails with same errors...

Most importantly all the errors are related to vite

{
  column: 36,
  file: '.....root/app/sanity/projectDetails.ts',
  length: 11,
  line: 19,
  lineText: "  typeof document === 'undefined' ? import.meta.env : window.ENV",
  namespace: '',
  suggestion: ''
}
Error reading ".....root/sanity.cli.ts": Cannot destructure property 'VITE_SANITY_PROJECT_ID' of '(intermediate value)(intermediate value)(intermediate value)' as it is undefined.
"import.meta" is not available with the "cjs" output format and will be empty
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

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
    at ~/....root/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:6869:13
    at Object.deployStudio [as default] (~/....root/node_modules/sanity/lib/_chunks-cjs/deployAction.js:24:18)
    at Object.action (~/....root/node_modules/sanity/lib/_chunks-cjs/_internal.js:1564:14)
error: "sanity" exited with code 1

Even after hard coding the project id and dataset, running npx sanity deploy I get this error

❯ bun sanity deploy
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
✔ Checking project info
✔ Clean output folder (7ms)
⠋ Build Sanity StudioThe CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
✖ Build Sanity Studio

Error: [vite]: Rollup failed to resolve import "~/sanity/projectDetails" from "/Users/.../sanity.config.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at viteWarn (file://~/Desktop/.../node_modules/sanity/node_modules/vite/dist/node/chunks/dep-52909643.js:48216:27)
    at onwarn (~/Desktop/.../node_modules/@vitejs/plugin-react/dist/index.cjs:258:9)
    at onRollupWarning (file://~/Desktop/..../node_modules/sanity/node_modules/vite/dist/node/chunks/dep-52909643.js:48245:9)
    at onwarn (file://~/Desktop/.../node_modules/sanity/node_modules/vite/dist/node/chunks/dep-52909643.js:47976:13)
    at file://~/Desktop/.../node_modules/sanity/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24276:13
    at Object.logger [as onLog] (file://~/Desktop/.../node_modules/sanity/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:25950:9)
    at ModuleLoader.handleInvalidResolvedId (file://~/Desktop/..../node_modules/sanity/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24862:26)
    at file://~/Desktop/....../node_modules/sanity/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24822:26
error: "sanity" exited with code 1
SimeonGriggs commented 7 months ago

sanity deploy is for standalone Vite-based Studios. This is a Remix project with an embedded Studio, designed to be deployed to Vercel for hosting.

trulymittal commented 7 months ago

@SimeonGriggs I understand that sanity deploy is for standalone projects, but in that case the recently released sanity schema extract as well as sanity typegen generate would also fail because of the above mentioned issue. Also to note is that sanity build also fails for the same reason.

Moreover, deploying to sanity cloud is a basic stuff that the next-studio or any other integration (afaik) of sanity does for sanity, Imo this should be supported.

Any help would be greatly appreciated.

SimeonGriggs commented 7 months ago

Right. So yes the way this project is currently setup, any CLI commands that need to access sanity.config.ts will fail because of the way the projectId and dataset variables are accessed.

Opening because it would be beneficial to have this fixed for commands like sanity schema extract and sanity graphql deploy but sanity deploy will not be supported.

timbakkum commented 3 weeks ago

Hi Simeon, I'm trying to use the groq typegen instead of zod on this template but running into the issue described. I thought loading the needed variables into the process would work, but I cannot get it to work. I've tried something like:

    "typegen": "dotenvx run -f .env.local -- pnpm sanity schema extract"

but somehow the sanity command doesn't pick up on the variables... any ideas for a fix? because process is undefined it tries to read the import.meta.env.VITE_ variables but that doesn't work either because we're not in vite context.