Comments (7)
Thanks for your report @dburles! We don't have a dual package hazard concern in this package, so we opted for 2.
๐
from next-sanity.
Looks great, thanks!
from next-sanity.
๐ This issue has been resolved in version 1.0.5 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐
from next-sanity.
I am receiving this error in Typescript when attempting to import the client:
// lib/sanity/index.ts
import { createClient } from 'next-sanity'
...
$ tsc --noEmit --strict --incremental false
lib/sanity/index.ts:1:30 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("next-sanity")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '***/package.json'.
1 import { createClient } from "next-sanity"
~~~~~~~~~~~~~
Found 1 error in lib/sanity/index.ts:1
This is on [email protected]
It seems the issue stems from moduleResolution: "Node16"
in the tsconfig.json, however we need this to leverage the "exports"
field in package.json for other imports. We have the "esModuleInterop" set to true in our tsconfig.json and I also tried "allowSyntheticDefaultImports" to no avail
Edit: I'm going to leave this here, but it seems the larger issue is the strange behavior with setting "Node16" as the resolution mode. This thread is a bit over my head: microsoft/TypeScript#49083 but it seems this particular method of module resolution is not to be used frivolously. We are going to work around the reasons we needed that import method as it likely implies issues with the modules that needed it.
Followup again: I don't know if we can actually refactor the places that require "Node16"
module resolution at this time. This is used to leverage the "exports" field of package.json in some internal packages. This could be an error on our end.
I can confirm at least for our use case, just slapping a // @ts-expect-error
above the import allows it to work fine with "moduleResolution": "Node16"
in tsconfig.json... so, not sure what the issue is exactly. we are going to try this out for now since continuing to us the Node16 resolution is a lot simpler in other areas of our codebase currently.
from next-sanity.
To further add to the confusion, this error is apparently not there in our netlify deploy which causes it to fail since I used a //@ts-expect-error
:
4:25:17 PM: $ yarn build
4:25:17 PM: yarn run v1.22.19
4:25:17 PM: $ next build
4:25:17 PM: info - Linting and checking validity of types...
4:25:19 PM: Failed to compile.
4:25:19 PM:
4:25:19 PM: ./lib/sanity/index.ts:2:1
4:25:19 PM: Type error: Unused '@ts-expect-error' directive.
4:25:19 PM: > 2 | // @ts-expect-error
4:25:19 PM: | ^
4:25:19 PM: 3 | import { createClient } from "next-sanity"
4:25:19 PM: 4 | import createImageUrlBuilder from "@sanity/image-url"
4:25:19 PM: 5 | import { config } from "./config"
unsure if this is some dependency difference or what.. I don't know how to run the same command that NextJS is outside of the build command
from next-sanity.
I think this is still an issue with this library, I believe the reason it seemed to "resolve" was because when NextJS builds it apparently forces "moduleResolution": "node"
according to the issue I referenced in the one below.
from next-sanity.
This problem should now be solved in v4
: https://github.com/sanity-io/next-sanity/releases/tag/v4.0.0 ๐
from next-sanity.
Related Issues (20)
- Scroll bar on mobile has a white background on dark mode HOT 1
- Upgrading to v8 of next-sanity causes multiple renderers concurrently rendering the same context provider warning HOT 6
- Content Translation Support HOT 1
- TypeError createClient is not a function HOT 3
- next-mdx-remote/rsc with next-sanity LiveQuery HOT 1
- ERR_MODULE_NOT_FOUND after updating to 8.2.1 HOT 2
- Errors or timeouts when running studio with `--turbo` flag HOT 6
- The page scrolls up randomly suddenly after autosave
- Cannot get final name for export 'Observable' of __barrel_optimize__ HOT 2
- parseBody outdated for Route Handlers in NextJS HOT 1
- Fix Migration Guides' links HOT 2
- useCdn warning even after setting it to false HOT 1
- Next.js 14: Data Not Updating Despite Changes, Tried Revalidation and 'no-store' Caching HOT 2
- how can i deploy my nextjs sanity project on hostinger HOT 1
- how can i deploy my nextjs sanity project on hostinger HOT 1
- Studio breaks at `/studio` URL with experimentalFeature: โwindowHistorySupport: trueโ HOT 1
- Conflicting Peer Dependency
- `_QueryParamsLikelyByMistake & QueryParams` Type Issue HOT 2
- Type errors, deprecation warnings, Node Engine warnings, having to install with --legacy-peer-deps
- ZeroWidthSpace in text HOT 2
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 next-sanity.