最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

environment variables - Error: Write token not found in Sanity write-client configuration (Next.js project) - Stack Overflow

matteradmin6PV0评论
 ✓ Starting...
 ⚠ Configuration with next.config.ts is currently an experimental feature, use with caution.
 ○ Compiling /instrumentation ...
 ✓ Compiled /instrumentation in 3.7s (865 modules)
 ✓ Ready in 8.6s
 ○ Compiling / ...
 ✓ Compiled / in 14.2s (4673 modules)
 ⨯ sanity\lib\write-client.ts (15:9) @ eval
 ⨯ Error: Write token not found.
    at eval (webpack-internal:///(rsc)/./sanity/lib/write-client.ts:21:11)
    at __webpack_require__.a (E:\Github\yc_directory\.next\server\webpack-runtime.js:108:13)
    at eval (webpack-internal:///(rsc)/./sanity/lib/write-client.ts:1:21)
    at (rsc)/./sanity/lib/write-client.ts (E:\Github\yc_directory\.next\server\app\(root)\page.js:1023:1)
    at __webpack_require__ (E:\Github\yc_directory\.next\server\webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./auth.ts:13:82)
    at __webpack_require__.a (E:\Github\yc_directory\.next\server\webpack-runtime.js:108:13)
    at eval (webpack-internal:///(rsc)/./auth.ts:1:21)
    at (rsc)/./auth.ts (E:\Github\yc_directory\.next\server\app\(root)\page.js:825:1)
    at __webpack_require__ (E:\Github\yc_directory\.next\server\webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./components/Navbar.tsx:15:63)
    at __webpack_require__.a (E:\Github\yc_directory\.next\server\webpack-runtime.js:108:13)
    at eval (webpack-internal:///(rsc)/./components/Navbar.tsx:1:21)
    at (rsc)/./components/Navbar.tsx (E:\Github\yc_directory\.next\server\app\(root)\page.js:836:1)
    at __webpack_require__ (E:\Github\yc_directory\.next\server\webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./app/(root)/layout.tsx:17:76)
    at __webpack_require__.a (E:\Github\yc_directory\.next\server\webpack-runtime.js:108:13)
    at eval (webpack-internal:///(rsc)/./app/(root)/layout.tsx:1:21)
    at (rsc)/./app/(root)/layout.tsx (E:\Github\yc_directory\.next\server\app\(root)\page.js:600:1)
    at Function.__webpack_require__ (E:\Github\yc_directory\.next\server\webpack-runtime.js:33:43)
    at async getLayoutOrPageModule (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:10688)
    at async createComponentTreeInternal (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:17321)
    at async E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:22038
    at async Promise.all (index 0)
    at async createComponentTreeInternal (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:21262)
    at async getRSCPayload (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:71871)
    at async renderToStream (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:91401)
    at async renderToHTMLOrFlightImpl (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:84078)
    at async doRender (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:1564:34)
    at async responseGenerator (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:1807:28)
    at async DevServer.renderToResponseWithComponentsImpl (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:1851:28)
    at async DevServer.renderPageComponent (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:2223:24)
    at async DevServer.renderToResponseImpl (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:2261:32)
    at async DevServer.pipeImpl (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:973:25)
    at async NextNodeServer.handleCatchallRenderRequest (E:\Github\yc_directory\node_modules\next\dist\server\next-server.js:281:17)
    at async DevServer.handleRequestImpl (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:866:17)  
    at async E:\Github\yc_directory\node_modules\next\dist\server\dev\next-dev-server.js:377:20
    at async Span.traceAsyncFn (E:\Github\yc_directory\node_modules\next\dist\trace\trace.js:157:20)
    at async DevServer.handleRequest (E:\Github\yc_directory\node_modules\next\dist\server\dev\next-dev-server.js:374:24)
    at async invokeRender (E:\Github\yc_directory\node_modules\next\dist\server\lib\router-server.js:183:21)
    at async handleRequest (E:\Github\yc_directory\node_modules\next\dist\server\lib\router-server.js:360:24)
    at async requestHandlerImpl (E:\Github\yc_directory\node_modules\next\dist\server\lib\router-server.js:384:13)     
    at async Server.requestListener (E:\Github\yc_directory\node_modules\next\dist\server\lib\start-server.js:142:13) {
  page: '/'
}
  13 |
  14 | if (!writeClient.config().token) {
> 15 |   throw new Error("Write token not found.");
     |         ^
  16 | }
  17 |
 ○ Compiling /_error ...
 ✓ Compiled /_error in 3.5s (5117 modules)

This is an open source code from the Github. I'm working on this Next.js project that uses Sanity as a CMS. However, I'm encountering an error related to the configuration of the Sanity client. Here is the error message I'm seeing in my terminal: Because I just need to create a env file and get the key. Then this will run correctly. javascript Error: Write token not found at eval (sanity\lib\write-client.ts:15:8)

What I Have Done: I created a Write Token in the Sanity dashboard and added it to my .env file:

makefile SANITY_WRITE_TOKEN=your_generated_token enter image description here And I tried several options here. It is not working.

 ✓ Starting...
 ⚠ Configuration with next.config.ts is currently an experimental feature, use with caution.
 ○ Compiling /instrumentation ...
 ✓ Compiled /instrumentation in 3.7s (865 modules)
 ✓ Ready in 8.6s
 ○ Compiling / ...
 ✓ Compiled / in 14.2s (4673 modules)
 ⨯ sanity\lib\write-client.ts (15:9) @ eval
 ⨯ Error: Write token not found.
    at eval (webpack-internal:///(rsc)/./sanity/lib/write-client.ts:21:11)
    at __webpack_require__.a (E:\Github\yc_directory\.next\server\webpack-runtime.js:108:13)
    at eval (webpack-internal:///(rsc)/./sanity/lib/write-client.ts:1:21)
    at (rsc)/./sanity/lib/write-client.ts (E:\Github\yc_directory\.next\server\app\(root)\page.js:1023:1)
    at __webpack_require__ (E:\Github\yc_directory\.next\server\webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./auth.ts:13:82)
    at __webpack_require__.a (E:\Github\yc_directory\.next\server\webpack-runtime.js:108:13)
    at eval (webpack-internal:///(rsc)/./auth.ts:1:21)
    at (rsc)/./auth.ts (E:\Github\yc_directory\.next\server\app\(root)\page.js:825:1)
    at __webpack_require__ (E:\Github\yc_directory\.next\server\webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./components/Navbar.tsx:15:63)
    at __webpack_require__.a (E:\Github\yc_directory\.next\server\webpack-runtime.js:108:13)
    at eval (webpack-internal:///(rsc)/./components/Navbar.tsx:1:21)
    at (rsc)/./components/Navbar.tsx (E:\Github\yc_directory\.next\server\app\(root)\page.js:836:1)
    at __webpack_require__ (E:\Github\yc_directory\.next\server\webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./app/(root)/layout.tsx:17:76)
    at __webpack_require__.a (E:\Github\yc_directory\.next\server\webpack-runtime.js:108:13)
    at eval (webpack-internal:///(rsc)/./app/(root)/layout.tsx:1:21)
    at (rsc)/./app/(root)/layout.tsx (E:\Github\yc_directory\.next\server\app\(root)\page.js:600:1)
    at Function.__webpack_require__ (E:\Github\yc_directory\.next\server\webpack-runtime.js:33:43)
    at async getLayoutOrPageModule (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:10688)
    at async createComponentTreeInternal (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:17321)
    at async E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:22038
    at async Promise.all (index 0)
    at async createComponentTreeInternal (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:21262)
    at async getRSCPayload (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:71871)
    at async renderToStream (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:91401)
    at async renderToHTMLOrFlightImpl (E:\Github\yc_directory\node_modules\next\dist\compiled\next-server\app-page-experimental.runtime.dev.js:157:84078)
    at async doRender (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:1564:34)
    at async responseGenerator (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:1807:28)
    at async DevServer.renderToResponseWithComponentsImpl (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:1851:28)
    at async DevServer.renderPageComponent (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:2223:24)
    at async DevServer.renderToResponseImpl (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:2261:32)
    at async DevServer.pipeImpl (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:973:25)
    at async NextNodeServer.handleCatchallRenderRequest (E:\Github\yc_directory\node_modules\next\dist\server\next-server.js:281:17)
    at async DevServer.handleRequestImpl (E:\Github\yc_directory\node_modules\next\dist\server\base-server.js:866:17)  
    at async E:\Github\yc_directory\node_modules\next\dist\server\dev\next-dev-server.js:377:20
    at async Span.traceAsyncFn (E:\Github\yc_directory\node_modules\next\dist\trace\trace.js:157:20)
    at async DevServer.handleRequest (E:\Github\yc_directory\node_modules\next\dist\server\dev\next-dev-server.js:374:24)
    at async invokeRender (E:\Github\yc_directory\node_modules\next\dist\server\lib\router-server.js:183:21)
    at async handleRequest (E:\Github\yc_directory\node_modules\next\dist\server\lib\router-server.js:360:24)
    at async requestHandlerImpl (E:\Github\yc_directory\node_modules\next\dist\server\lib\router-server.js:384:13)     
    at async Server.requestListener (E:\Github\yc_directory\node_modules\next\dist\server\lib\start-server.js:142:13) {
  page: '/'
}
  13 |
  14 | if (!writeClient.config().token) {
> 15 |   throw new Error("Write token not found.");
     |         ^
  16 | }
  17 |
 ○ Compiling /_error ...
 ✓ Compiled /_error in 3.5s (5117 modules)

This is an open source code from the Github. https://github/adrianhajdin/yc_directory I'm working on this Next.js project that uses Sanity as a CMS. However, I'm encountering an error related to the configuration of the Sanity client. Here is the error message I'm seeing in my terminal: Because I just need to create a env file and get the key. Then this will run correctly. javascript Error: Write token not found at eval (sanity\lib\write-client.ts:15:8)

What I Have Done: I created a Write Token in the Sanity dashboard and added it to my .env file:

makefile SANITY_WRITE_TOKEN=your_generated_token enter image description here And I tried several options here. It is not working.

Share Improve this question asked Nov 18, 2024 at 13:22 yi lanyi lan 11 bronze badge 1
  • "enter image description here" is not a good description of an image. You should edit your question and describe, in words, what information you hope the image will give the reader. – Wyck Commented Nov 18, 2024 at 13:37
Add a comment  | 

1 Answer 1

Reset to default 0

Adding the following code to next.config.ts worked for me:

module.exports = {
  env: {
    SANITY_API_WRITE_TOKEN: process.env.SANITY_API_WRITE_TOKEN,
  },
}

Next doesn't expose environment variables to the client by default. If your code is running in the client-side browser, you need to explicitly expose it in next.config.ts.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far