Comments (5)
@max888 how are you including Sanity component inside nextjs, from the code provided that shouldn't have any issues. Possible that the imports are incorrect in some place. If you can provide example recreating the issue it would help in debugging further.
from sanity.
I just clone it, it was working fine with pnpm.
from sanity.
Hi @binoy14 I have a 'sanity' folder in the root of my nextjs application (outside of the app folder).
Then I have a file located in @/app/lib/sanity
with the following code to connect to the client:
import { createClient } from 'next-sanity'
import imageUrlBuilder from '@sanity/image-url'
export const client = createClient({
projectId: "xxxxxxx", // replaced with my real id
dataset: "production",
apiVersion: "2024-01-01",
// unless you have caching for your front end, `useCdn` should be `true` for most production environments
useCdn: true,
})
const builder = imageUrlBuilder(client)
export function urlFor(source) {
return builder.image(source)
}
Then throughout the nextjs app I import the sanity client or image builder in my components using:
import { urlFor } from "@/app/lib/sanity.js";
import { client } from "@/app/lib/sanity.js";
The weird thing is that if I extract/copy this 'sanity' folder somewhere outside of the nextjs application and run it using npm run dev
, it works fine. It's only when I try and run it whilst inside the nextjs app that I get the issue. However, in the 'sanity' folder I'm not making any references to code in the nextjs app. I'm just defining schemas. That's why I'm not sure how there is an error there when trying to run it.
I will try and make an example recreating the issue to help debug.
from sanity.
Do you have a "baseUrl"
configuration in your tsconfig.json
?
from sanity.
Hi @mariuslundgard thanks for following up. I am not using typescript for my project but in my jsconfig.json
I have have a `"baseUrl" set like this:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
}
}
I 'fixed' the issue by moving the sanity part into a new sub folder within the project and it worked. Seemed to me like it could have been a weird npm caching issue. Although I had tried npm cache clean
and a few other things with no luck.
My nextjs app folder structure was:
/app
-layout.js
- page.js
- etc...
/sanity
/schemaTypes
-sanity.cli.js
-sanity.config.js
-package.json
-etc...
jsconfig.json
next-config.mjs
package.json
...etc
I then moved the /sanity
folder to a different subfolder at /new/sanity
, ran npm run dev
and it worked.
from sanity.
Related Issues (20)
- Sanity npm package throws type error on build HOT 3
- Ability to order documents using an array value
- Hide schedule action in some documents
- Unable to upload images to block content type field on Safari
- Introduce Selective CLI Logging Suppression
- How can I restrict access to resources only through my domain? HOT 2
- TypeGen not generating union type for string array with list option
- can't use `npx @sanity/cli init --template shopify` with the next.js embedded studio option
- On >3.41.0 dragging blocks in PTE gives "Can't upload this file here" error HOT 1
- TypeGen generates Array<never> for query using "in" HOT 1
- TypeGen generates Array<never> for query using chained parent operator
- Hang introduced by #5269, (a0f93cb) (fix included) HOT 3
- Typegen: Can't generate types with conditional values in slice and ordering operations even when the it doesn't effect the type. HOT 2
- All Studio UI menus broken/empty in Dev HOT 1
- Both new and legacy search don't work with documents with a custom title field
- Desk tool crash: editOpsOf does not expect a draft id HOT 1
- throw new Error("'block' type is not defined in this schema (required).");
- Cannot Paste Into Block Content HOT 1
- Provide HTML as a content type for rich text
- The structure tool crashed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanity.