使用本地环境测试I/O的稳定性

huangapple go评论63阅读模式
英文:

Using local env to test sanity IO

问题

以下是您提供的代码部分的翻译:

Uncaught error: Can't find variable: process
http://localhost:3333/sanity.config.ts:5:26

出现错误:

未捕获的错误:无法找到变量:process
http://localhost:3333/sanity.config.ts:5:26

It is with the .env.local file. I found this by entering my project ID directly into the sanity config file. However, I am trying to figure why my .env.local file will not work. I have noticed from watching a tutorial my .env file does not have the little gear icon that other people had. Why is that?

这与 .env.local 文件有关。我通过将我的项目ID直接输入到 sanity 配置文件中找到了这个问题。但是,我正在尝试弄清楚为什么我的 .env.local 文件无法工作。我注意到从教程中观察到,我的 .env 文件没有其他人拥有的小齿轮图标。为什么呢?

here is my .en.local file:

这是我的 .env.local 文件:

NEXT_PUBLIC_SANITY_PROJECT_ID= xxxxxx
NEXT_PUBLIC_SANITY_DATASET= production
NEXT_PUBLIC_SANITY_API_VERSION=2022-11-15

see pic

这是我的 .env.local 文件:

NEXT_PUBLIC_SANITY_PROJECT_ID= xxxxxx
NEXT_PUBLIC_SANITY_DATASET= production
NEXT_PUBLIC_SANITY_API_VERSION=2022-11-15

查看图片

here is the sanity.config.ts file pulling using env.local file:

这是使用 env.local 文件的 sanity.config.ts 文件:

import {defineConfig} from 'sanity'
import {deskTool} from 'sanity/desk'
import {visionTool} from '@sanity/vision'
import {schemaTypes} from './schemas'

const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET!

export default defineConfig({
   name: 'Jeremy',
   title: 'Sanity Stuff',

  projectId,
  dataset,

  plugins: [deskTool(), visionTool()],

  schema: {
    types: schemaTypes,
  },
})

这是使用 env.local 文件的 sanity.config.ts 文件:

import {defineConfig} from 'sanity'
import {deskTool} from 'sanity/desk'
import {visionTool} from '@sanity/vision'
import {schemaTypes} from './schemas'

const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET!

export default defineConfig({
   name: 'Jeremy',
   title: 'Sanity Stuff',

  projectId,
  dataset,

  plugins: [deskTool(), visionTool()],

  schema: {
    types: schemaTypes,
  },
})

tsconfig.json:

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "baseUrl": ".",
    "paths": {
      "@/": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

package.json in sanity project folder:

sanity项目文件夹中的package.json:

{
  "name": "sanity-stuff",
  "private": true,
  "version": "1.0.0",
  "main": "package.json",
  "license": "UNLICENSED",
  "scripts": {
    "dev": "sanity dev",
    "start": "sanity start",
    "build": "sanity build",
    "deploy": "sanity deploy",
    "deploy-graphql": "sanity graphql deploy"
  },
  "keywords": [
    "sanity"
  ],
  "dependencies": {
    "@portabletext/react": "^2.0.1",
    "@sanity/image-url": "^1.0.2",
    "@sanity/vision": "^3.0.0",
    "dotenv": "^16.0.3",
    "envdot": "^0.0.3",
    "next": "^13.1.6",
    "next-sanity": "^4.1.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-is": "^18.2.0",
    "sanity": "^3.0.0",
    "styled-components": "^5.2.0"
  },
  "devDependencies": {
    "@sanity/eslint-config-studio": "^2.0.1",
    "eslint": "^8.6.0",
    "prettier": "^2.8.4",
    "typescript": "^4.0.0"
  },
  "prettier": {
    "semi": false,
    "printWidth": 100,
    "bracketSpacing": false,
    "singleQuote": true
  }
}

以上就是您提供的代码部分的翻译。如有其他需要,请随时告诉我。

英文:

The error is:

Uncaught error: Can't find variable: process
http://localhost:3333/sanity.config.ts:5:26

It is with the .env.local file. I found this by entering my project ID directly into the sanity config file. However, I am trying to figure why my .env.local file will not work. I have noticed from watching a tutorial my .env file does not have the little gear icon that other people had. Why is that?

here is my .en.local file:

NEXT_PUBLIC_SANITY_PROJECT_ID= xxxxxx
NEXT_PUBLIC_SANITY_DATASET= production
NEXT_PUBLIC_SANITY_API_VERSION=2022-11-15

see pic

here is the sanity.config.ts file pulling using env.local file:

import {defineConfig} from 'sanity'
import {deskTool} from 'sanity/desk'
import {visionTool} from '@sanity/vision'
import {schemaTypes} from './schemas'

const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET!


export default defineConfig({
   name: 'Jeremy',
   title: 'Sanity Stuff',

  projectId,
  dataset,

  plugins: [deskTool(), visionTool()],

  schema: {
    types: schemaTypes,
  },
 })

tsconfig.json:

 {
  "compilerOptions": {
   "target": "es5",
   "lib": ["dom", "dom.iterable", "esnext"],
   "allowJs": true,
   "skipLibCheck": true,
   "strict": true,
   "forceConsistentCasingInFileNames": true,
   "noEmit": true,
   "esModuleInterop": true,
   "module": "esnext",
   "moduleResolution": "node",
   "resolveJsonModule": true,
   "isolatedModules": true,
   "jsx": "preserve",
   "incremental": true,
   "baseUrl": ".",
   "paths": {
      "@/*": ["./*"]
   }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

package.json in sanity project folder:

  {
   "name": "sanity-stuff",
   "private": true,
   "version": "1.0.0",
   "main": "package.json",
   "license": "UNLICENSED",
   "scripts": {
     "dev": "sanity dev",
     "start": "sanity start",
    "build": "sanity build",
    "deploy": "sanity deploy",
    "deploy-graphql": "sanity graphql deploy"
  },
  "keywords": [
    "sanity"
  ],
   "dependencies": {
    "@portabletext/react": "^2.0.1",
    "@sanity/image-url": "^1.0.2",
    "@sanity/vision": "^3.0.0",
    "dotenv": "^16.0.3",
    "envdot": "^0.0.3",
    "next": "^13.1.6",
    "next-sanity": "^4.1.2",
    "react": "^18.2.0",
   "react-dom": "^18.2.0",
    "react-is": "^18.2.0",
    "sanity": "^3.0.0",
    "styled-components": "^5.2.0"
  },
  "devDependencies": {
   "@sanity/eslint-config-studio": "^2.0.1",
   "eslint": "^8.6.0",
   "prettier": "^2.8.4",
   "typescript": "^4.0.0"
  },
 "prettier": {
 "semi": false,
 "printWidth": 100,
 "bracketSpacing": false,
 "singleQuote": true
  }
 }

答案1

得分: 1

Sanity Studio有他们自己的环境变量规范。

> 您还可以使用SANITY_STUDIO_前缀向Studio环境中添加自己的变量,并且在本地开发时可以使用所谓的“dot env”(.env)文件更轻松地管理环境变量。

英文:

Sanity Studio has their own convention for environment variables.

> You can also add your own variables to the Studio environment with the SANITY_STUDIO_ prefix, and you can use so-called “dot env” (.env) files to more easily manage environment variables when developing locally.

huangapple
  • 本文由 发表于 2023年2月14日 05:56:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441593.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定