简体   繁体   English

本地主机:3000 更改代码后不显示任何内容

[英]Localhost:3000 not displaying anything after changing code

I'm following along a javascript tutorial, and suddenly localhost:3000 is not displaying anything but a white page after making some changes in my About.jsx file.我正在关注一个 javascript 教程,突然 localhost:3000 在我的 About.jsx 文件中进行了一些更改后,除了一个白页之外什么都没有显示。

It started happening after I added:它在我添加后开始发生:

import { urlFor, client } from '../../client';

and

const [abouts, setAbouts] = useState([]);

  useEffect(() => {
    const query = '*[_type == "abouts"]';

    client.fetch(query)
      .then((data) => {
        setAbouts(data);
      })
  }, []); 

If I undo the changes, hit save after adding one change at a time, it's fine.如果我撤消更改,一次添加一个更改后点击保存,就可以了。 But once all of them are in place, Chrome doesn't display anything.但是一旦所有这些都到位,Chrome 就不会显示任何内容。

I've tried adding an error in my code to see what happens, and the browser immediately picks up on it displaying it in red, so apparently it's not NOT working.我尝试在我的代码中添加一个错误以查看发生了什么,并且浏览器立即将其显示为红色,因此显然它不起作用。

Any idea what's happening?知道发生了什么吗? I've also tried deleting all cookies/browser history/caches with no luck.我也尝试过删除所有 cookie/浏览器历史记录/缓存,但没有成功。

EDIT: Tested a bit more now, and it really seems like the import is the culprit here.编辑:现在进行了更多测试,似乎进口是这里的罪魁祸首。 I followed the tutorial to at, but one thing that puzzled me was that I have no folder called client.我按照教程进行操作,但让我感到困惑的一件事是我没有名为 client 的文件夹。 It's a client.js file inside my src folder, but that's what the tutorial dude did, and so far in the video it still works for him, so... still confused.这是我的 src 文件夹中的 client.js 文件,但这就是教程老兄所做的,到目前为止,在视频中它仍然适用于他,所以......仍然很困惑。

My client.js file looks like this:我的 client.js 文件如下所示:

import sanityClient from '@sanity/client';
import imageUrlBuilder from '@sanity/image-url';

export const client = 'sanityClient'({
    projectID: process.env.REACT_APP_SANITY_PROJECT_ID,
    dataset: 'production',
    apiVersion: '2022-02-01',
    useCDN: true,
    token: process.env.REACT_APP_SANITY_TOKEN
});

const builder = imageUrlBuilder(client);

export const urlFor = (source) => builder.image(source);

I found the error, and now I'm deciding between jumping for joy or just jumping into a lake, lol.我发现了错误,现在我正在决定是高兴地跳还是跳进湖里,哈哈。

Apparently, it IS a big deal if you write 'projectID' when it should be 'projectId'..!显然,如果你在应该是 'projectId' 的时候写 'projectID' 是一件大事..!

Who knew!谁知道! Happy Saturday, everyone :)祝大家周六快乐:)

EDIT: And I had to remove the '' from编辑:我不得不从

export const client = sanityClient({

I thought about deleting this question since I figured it out myself, but maybe this will be to some help for anyone else sometime, so I'll leave it up.我想删除这个问题,因为我自己想通了,但也许这会对其他人有所帮助,所以我会保留它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM