无法构建 React/Next 项目 - 找到没有 React 组件的页面作为默认导出(上下文 api 文件) [英] Can't build React/Next project - found page without a React Component as default export (context api file)

查看:215
本文介绍了无法构建 React/Next 项目 - 找到没有 React 组件的页面作为默认导出(上下文 api 文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建我的 Next.js 项目,但它一直在终端中给我这个错误:

I'm trying to build my Next.js project but it keeps giving me this error in the terminal:

Error: Build optimization failed: found page without a React Component as default export in 
pages/components/context/Context

那是 React 上下文 API 文件,那里不应该有任何默认导出.这是错误还是什么?

That's the React context API file, there isn't supposed to be any default export there. Is this a bug or what?

推荐答案

您应该将 components 移到 pages 文件夹之外.pages/ 应仅用于页面组件,因为 Next.js 路由基于其结构.

You should move your components outside the pages folder. pages/ should only be used for page components as Next.js routing is based on its structure.

Next.js 有一个基于页面概念的基于文件系统的路由器.

Next.js has a file-system based router built on the concept of pages.

当一个文件被添加到 pages 目录时,它会自动作为路由使用.

When a file is added to the pages directory it's automatically available as a route.

这篇关于无法构建 React/Next 项目 - 找到没有 React 组件的页面作为默认导出(上下文 api 文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆