Giter VIP home page Giter VIP logo

Comments (8)

markomitranic avatar markomitranic commented on May 23, 2024 1

I am facing a similar issue to this, but the error message I get is:

✖ Could not find binding for import "useLocale" in next-intl in "../src/app/[locale]/trails/page.tsx"

This is the relevant code from my ../src/app/[locale]/trails/page.tsx file:

import { groq } from 'next-sanity';
import { useLocale } from 'next-intl';

export default async function Trails() {
  const locale = useLocale();
  const TRAILS_QUERY = groq`*[_type == "trail" && language == "${locale}"]{
    _id,
    name
  }`;

I need the locale parameter to be dynamic based on the user's locale, so this issue is blocking me from using TypeGen in my project.

Hey, in your case that is a different issue, you should be using prepared queries, so you would not be concatenating strings at all, you would send the locale param as a second argument

example

sanityClient.fetch(
  `*[_type == "orders" && orderId.current == $orderId][0]{...}`,
  {orderId: query.orderId}
)

from sanity.

sgulseth avatar sgulseth commented on May 23, 2024 1

Thanks a lot! I have a fix lined up here #6540

from sanity.

hb20007 avatar hb20007 commented on May 23, 2024

I am facing a similar issue to this, but the error message I get is:

✖ Could not find binding for import "useLocale" in next-intl in "../src/app/[locale]/trails/page.tsx"

This is the relevant code from my ../src/app/[locale]/trails/page.tsx file:

import { groq } from 'next-sanity';
import { useLocale } from 'next-intl';

export default async function Trails() {
  const locale = useLocale();
  const TRAILS_QUERY = groq`*[_type == "trail" && language == "${locale}"]{
    _id,
    name
  }`;

I need the locale parameter to be dynamic based on the user's locale, so this issue is blocking me from using TypeGen in my project.

from sanity.

hb20007 avatar hb20007 commented on May 23, 2024

I am facing a similar issue to this, but the error message I get is:
✖ Could not find binding for import "useLocale" in next-intl in "../src/app/[locale]/trails/page.tsx"
This is the relevant code from my ../src/app/[locale]/trails/page.tsx file:

import { groq } from 'next-sanity';
import { useLocale } from 'next-intl';

export default async function Trails() {
  const locale = useLocale();
  const TRAILS_QUERY = groq`*[_type == "trail" && language == "${locale}"]{
    _id,
    name
  }`;

I need the locale parameter to be dynamic based on the user's locale, so this issue is blocking me from using TypeGen in my project.

Hey, in your case that is a different issue, you should be using prepared queries, so you would not be concatenating strings at all, you would send the locale param as a second argument

example

sanityClient.fetch(
  `*[_type == "orders" && orderId.current == $orderId][0]{...}`,
  {orderId: query.orderId}
)

Thanks, and it's working for me now. Concatenation was working for me to get the data so I assumed that the issue was with sanity typegen. Now only the original issue which you reported remains.

from sanity.

georgeosutton avatar georgeosutton commented on May 23, 2024

#6457 Does not seems to fix all cases still getting Cannot find module if I use relative imports. Seems to happen when I have a fragments composed of other fragments.

from sanity.

sgulseth avatar sgulseth commented on May 23, 2024

@georgeosutton Do you have a reproduction either in a repo or a gist somewhere?

from sanity.

georgeosutton avatar georgeosutton commented on May 23, 2024

@sgulseth reproduction here

I've added a folder with relevant fragments / query.

I get the following when I run pnpm run typegen

Cannot find module 'C:\Users\George\Documents\GitHub\typegen-reproduction\fragments\image'
Require stack:
- C:\Users\George\Documents\GitHub\typegen-reproduction\node_modules\.pnpm\@[email protected]\node_modules\@sanity\codegen\lib\index.js   
- C:\Users\George\Documents\GitHub\typegen-reproduction\node_modules\.pnpm\@[email protected]\node_modules\@sanity\cli\lib\workers\typegenGenerate.js in "./src/sanity/lib/queries.ts"

from sanity.

sgulseth avatar sgulseth commented on May 23, 2024

fix for this was released yesterday, v3.41.0

from sanity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.