Skip to content
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

Typegen error - Failed to load configuration - sanity.defineLocaleResourceBundle is not a function #8646

Open
theolvq opened this issue Feb 14, 2025 · 4 comments

Comments

@theolvq
Copy link

theolvq commented Feb 14, 2025

Describe the bug

When running typegen script, I get the following TypeError

TypeError: Failed to load configuration file "<path>/sanity.config.ts":
sanity.defineLocaleResourceBundle is not a function
    at Object.<anonymous> (~/<path>/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+theme-on_43559562270dfec2382bb09dbb7873c0/node_modules/@sanity/vision/src/i18n/index.ts:15:44)
    at Object.newLoader [as .js] (~/<path>/node_modules/.pnpm/[email protected][email protected]/node_modules/esbuild-register/dist/node.js:2262:9)
    at extensions..js (~/<path>/node_modules/.pnpm/[email protected][email protected]/node_modules/esbuild-register/dist/node.js:4833:24)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
 ELIFECYCLE  Command failed with exit code 1.

Weirdly, nothing has changed on my end and this happens even on older branches.

To Reproduce

Steps to reproduce the behavior:

  1. Make sure you have the following script in your package.json
    "typegen": "sanity schema extract --enforce-required-fields && sanity typegen generate"
  2. Make sure you have a sanity-typegen.json file correctly setup
  3. run typegen script (in my case pnpm typegen
  4. See error

Expected behavior

Typegen should happen without error

Screenshots
If applicable, add screenshots to help explain your problem.

Which versions of Sanity are you using?

@sanity/cli (global) 3.73.0 (latest: 3.75.0)
@sanity/asset-utils 2.2.1 (up to date)
@sanity/cli 3.74.1 (latest: 3.75.0)
@sanity/color-input 4.0.3 (up to date)
@sanity/eslint-config-studio 5.0.1 (up to date)
@sanity/icons 3.5.7 (latest: 3.6.0)
@sanity/ui 2.11.8 (latest: 2.13.0)
@sanity/vision 3.74.1 (latest: 3.75.0)
sanity 3.74.1 (latest: 3.75.0)

What operating system are you using?
MacOS latest

Which versions of Node.js / npm are you running?

Node v22.13.1
pnpm 10.2.0

Additional context

If I remove the vision plugin from sanity config, the typegen happens without an issue.

@Ayberkyvs
Copy link

Ayberkyvs commented Feb 19, 2025

The similar error occurs for me as well. I've tried it with both LTS and Current Node.js versions, and even with pnpm and yarn. I've deleted node_modules multiple times. Unfortunately, while the error occurs locally, it works flawlessly when pushed to Vercel.

✗ Failed to extract schema, with enforced required fields

ReferenceError: Failed to load configuration file "C:/Users/Username/Documents/GitHu
b/reformmarine-v2/sanity.config.ts":
require is not defined
    at file:///C:/Users/Username/Documents/GitHub/reformmarine-v2/node_modules/lucid
e-react/dist/cjs/lucide-react.js:10:13
    at Object.newLoader [as .js] (C:/Users/Username/Documents/GitHub/reformmarine-v2
/node_modules/esbuild-register/dist/node.js:2262:9)
    at extensions..js (C:/Users/Username/Documents/GitHub/reformmarine-v2/node_modul
es/esbuild-register/dist/node.js:4833:24)
error 
Command failed with exit code 1.
@sanity/cli (global)  3.76.1 (up to date)
@sanity/image-url      1.1.0 (up to date)
@sanity/vision        3.76.1 (up to date)
sanity                3.76.1 (up to date)
Tested On

Node: v22.14.0 - v23.7.0
pnpm: 9.15.x - 10.4.0
yarn: v1.22.22

Need help ASAP. Thanks!

@theolvq
Copy link
Author

theolvq commented Feb 20, 2025

I managed to solve this by removing node_modules/ and reinstalling. However it came back a little bit later and I have to delete node_modules/ once a day to run typegen.

@Ayberkyvs
Copy link

I managed to solve this by removing node_modules/ and reinstalling. However it came back a little bit later and I have to delete node_modules/ once a day to run typegen.

At first, deleting node_modules worked for me too. But it doesn’t affect at all anymore. I get a TypeScript error because there is currently no type in my project. In order to solve the problem, the typegen needs to create schemes, so my project is frozen and waiting for a solution without working. Also, there was a typegen in my previous project and it worked smoothly, but when I updated to dependencies even though the project was over, the same error started there.

@Ayberkyvs
Copy link

Hello, I found the root cause of my issue, and through research, I learned that the source of typegen errors is usually related to schema definitions. I recommend reviewing your schema. @theolvq Happy coding!

#8718

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

2 participants