[英]Why does changing app.js to app.tsx break my Next.js project?
I'm trying to set up the Next.js framework with TypeScript, and I'm able to change my pages/index.js
page to an pages/index.tsx
page without issue, but when I attempt to change pages/_app.js
to pages/_app.tsx
, the project breaks with the error:我正在尝试使用 TypeScript 设置 Next.js 框架,并且可以毫无问题地将我的pages/index.js
页面更改为pages/index.tsx
页面,但是当我尝试更改pages/_app.js
到pages/_app.tsx
,项目因错误而中断:
Error: ENOENT: no such file or directory, open /../../pages/_app.js
错误:ENOENT:没有/../../pages/_app.js
文件或目录,打开/../../pages/_app.js
Why is this happening?为什么会这样? I've installed TypeScript, @types/react, and @types/node我已经安装了 TypeScript、@types/react 和 @types/node
You may do the following您可以执行以下操作
npm run dev
关闭脚本即npm run dev
npm run dev
).再次运行应用程序 ( npm run dev
)。 It should work now.它现在应该可以工作了。I think it is a problem with caching我认为这是缓存的问题
Create an empty tsconfig.json
file in the root of your project.在项目的根目录中创建一个空的tsconfig.json
文件。
The then run run next dev
然后运行run next dev
Stop the script from running ctrl+c (Mac) on terminal.停止脚本在终端上运行 ctrl+c (Mac)。
Write this in _app.tsx: export default function App({ Component, pageProps }: AppProps): JSX.Element { return <Component {...pageProps} /> }
_app.tsx 中这样写: export default function App({ Component, pageProps }: AppProps): JSX.Element { return <Component {...pageProps} /> }
Re-run the script npm run dev重新运行脚本 npm run dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.