ContentfulReact .env.environment 文件错误

问题描述

我在客户端文件夹中创建了一个包含内容丰富的 api 的博客,api 密钥位于 .env.devlopment 文件中。我还有一个 .env 文件,用于将 cloudinary 的 api 密钥保存在同一个客户端文件夹中。当我测试我的 React 站点时,我可以看到我的所有内容并上传音频,但是在终端中运行 npm run build 时出现问题。我在本地主机中没有错误,但是当我准备部署到 heroku 时收到了 Expected parameter accessToken 错误。我从 index.js 文件中的 ReactDOM.render 中删除了 ReactDOM,我收到了一个关于替换 ReactDOM.render 调用的问题。

contentful.js 文件:

import {createClient} from 'contentful';

export default createClient({
  space: process.env.REACT_APP_API_SPACE,accessToken: process.env.REACT_APP_ACCESS_TOKEN
});

.env.enviroment file:

 REACT_APP_API_SPACE= my access key
 REACT_APP_ACCESS_TOKEN= my access token

运行 npm run build 时终端出错

Error: Uncaught [TypeError: Expected parameter accessToken]
Object.t.createClient 
'render' from react-snapshot was never called. Did you replace the call to ReactDOM.render()?

当我运行 console.log(process.env);我收到

console.log(process.env);
1.  {NODE_ENV: "development",PUBLIC_URL: "",WDS_SOCKET_HOST: undefined,WDS_SOCKET_PATH: undefined,WDS_SOCKET_PORT: undefined,…}
1.  FAST_REFRESH: true
2.  NODE_ENV: "development"
3.  PUBLIC_URL: ""
4.  REACT_APP_API: "http://localhost:8000/api"
5.  REACT_APP_CLOUDINARY_CLOUD_NAME: "********"
6.  REACT_APP_CLOUDINARY_UPLOAD_SECRET: "*******"
7.  REACT_APP_SPACE_ID: "*********"
8.  REACT_APP_SPACE_TOKEN: "***********"

client.env

REACT_APP_API: "http://localhost:8000/api"
    REACT_APP_CLOUDINARY_CLOUD_NAME: "********"
    REACT_APP_CLOUDINARY_UPLOAD_SECRET: "*******"

client.env.development

REACT_APP_SPACE_ID: "*********"
 REACT_APP_SPACE_TOKEN: "***********"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)