Next.js _app.js:模块解析失败:新项目上出现意外标记

Mik*_*sen 7 javascript reactjs next.js

我使用以下命令创建一个新的 Next.js 项目:

npx create-next-app
Run Code Online (Sandbox Code Playgroud)

然后我进入该文件夹,运行npm run dev并收到以下错误:

C:/Users/mikke/Documents/Projects/next-project/pages/_app.js 4:9
Module parse failed: Unexpected token (4:9)
You may need an appropriate loader to handle this file type, currently no loaders are 
configured to process this file. See https://webpack.js.org/concepts#loaders
|
| function MyApp({ Component, pageProps }) {
>   return <Component {...pageProps} />
| }
|
Run Code Online (Sandbox Code Playgroud)

非常困惑为什么会发生这种情况。我首先在部署然后克隆此示例时遇到错误:https://github.com/supabase/supabase/tree/master/examples/nextjs-todo-list

我还尝试删除 node_modules 和 ./next 并重新安装依赖项,但没有运气。我缺少什么?

编辑:我的 _app.js (与 create-next-app 默认值完全相同)

import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

export default MyApp
Run Code Online (Sandbox Code Playgroud)

Mik*_*sen 1

对于其他可能遇到此问题的人,解决方案(至少对我来说)是在 vscode 终端内运行命令。欲了解更多信息:https ://github.com/vercel/next.js/issues/16535