SimeonGriggs / sanity-react-router-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

Sanity CLI command doesn't work if `type: module` is present in `package.json` #65

Closed SimeonGriggs closed 8 months ago

SimeonGriggs commented 8 months ago

When you first clone this repo you're prompted to run a Sanity CLI script to populate the dataset.

npx sanity@latest exec ./scripts/createData.ts --with-user-token

But, when type: module is present in package.json it yields an error in Node

node:internal/modules/esm/get_format:160
  throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath);
        ^

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/simeongriggs/Sites/sanity-remix-template/scripts/createData.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:143:22)
    at async ModuleLoader.load (node:internal/modules/esm/loader:409:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45)
    at async link (node:internal/modules/esm/module_job:76:21) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

Node.js v20.11.0

Removing it makes the CLI work, but then produces this warning during development

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.
SimeonGriggs commented 8 months ago

This is an issue with Sanity itself and a workaround is posted here.