简体   繁体   English

Next.js/Square API 错误:Fetch API 无法加载。 不支持 URL 方案“webpack-internal”

[英]Next.js/Square API error: Fetch API cannot load. URL scheme "webpack-internal" is not supported

I'm having this error when trying to pull stock from Square API.尝试从 Square API 提取库存时出现此错误。

injectGlobalHook.js:1648 Fetch API cannot load webpack-internal:///./node_modules/@next/react-dev-overlay/lib/internal/ReactDevOverlay.js. URL scheme "webpack-internal" is not supported.

I'm converting my React.js project into Next.js, so I'm just trying to learn the differences between the two.我正在将我的 React.js 项目转换为 Next.js,所以我只是想了解两者之间的差异。

Initially, I pulled the data with a proxy in my config file to avoid a CORS Error , but knew that was just a workaround for the time being because I needed to hide the API_KEY .最初,我使用config文件中的proxy提取数据以避免CORS Error ,但我知道这只是暂时的解决方法,因为我需要隐藏API_KEY

Now I'm trying to call the API the right way in Next.js backend options with getServerSideProps现在我正在尝试使用getServerSideProps在 Next.js 后端选项中以正确的方式调用 API

export async function getStaticProps() {
  const allStockObjects = await fetch(requests.fetchAllStock, {
    method: "GET",
    headers: headers,
  })
    .then((res) => res.json)
    .catch((err) => console.log(err));

  return {
    props: {
      allStockObjects,
    },
  };
}

Here is my export, but I have the exact same export in a Component with a POST request done the same way to the same Square API and it works perfectly fine.这是我的导出,但我在一个组件中有完全相同的导出, POST请求以相同的方式完成到相同的 Square API,它工作得非常好。

I also check my APILogs on my Square Dashboard and the request never makes it to the API at all.我还在 Square Dashboard 上检查了我的APILogs ,但请求根本没有发送到 API。

Not much online on this error or Square API for that matter, so I hope someone could help.关于此错误或 Square API 的在线信息并不多,所以我希望有人能提供帮助。

I just ran into a similar issue.我刚刚遇到了类似的问题。 For reference I am taking Wes Bos's course on React/ GraphQL.作为参考,我正在学习 Wes Bos 的 React/GraphQL 课程。 To get past the issue I shut down the frontend and then deleted the .next folder.为了解决这个问题,我关闭了前端,然后删除了 .next 文件夹。 Then re-ran the frontend so a new .next folder gets generated.然后重新运行前端,以便生成一个新的 .next 文件夹。 I also cleared the browser cache.我还清除了浏览器缓存。 After that the issue went away for me.在那之后,这个问题对我来说就消失了。

这个问题是由 React Devtoools 引起的,特别是设置Always parse hook names from source (may be slow) ——如果你在不需要时关闭它,它将防止错误。

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

相关问题 fetch api 无法加载,不支持 url 方案“文件” - fetch api cannot load, url scheme 'file' is not supported 使用 getServerSideProps 获取内部 API? (下一个.js) - Internal API fetch with getServerSideProps? (Next.js) Fetch API 无法加载 localhost:3000/send。 不支持 URL 方案“localhost” - Fetch API cannot load localhost:3000/send. URL scheme "localhost" is not supported 内部 Next.js API 调用返回 500 错误 - Internal Next.js API call returns 500 Error 提取Api无法加载Webpack - Fetch Api cannot load webpack JSON.parse 位置 0 处的 JSON 中的意外标记 J (<anonymous> ) 在 __webpack_exports__.default (webpack-internal:///./pages/api/mail.js:4:21) - Unexpected token J in JSON at position 0 at JSON.parse (<anonymous>) at __webpack_exports__.default (webpack-internal:///./pages/api/mail.js:4:21) Next.JS:无法在 getInitialProps 中调用内部 API。 得到错误:读取 ECONNRESET - Next.JS: Can't call Internal API in getInitialProps. Got Error: read ECONNRESET 从本地 API Next.js 获取数据 - Fetch data from local API Next.js 如何在 Next.js 中进行依赖获取 API 调用 - How to make dependent fetch API calls in Next.js Next.js 在初始渲染时从 api 获取令牌并存储它 - Next.js fetch a token from an api on initial render and store it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM