简体   繁体   English

在反应应用程序中将 index.js 重命名为 index.jsx

[英]Renaming index.js to index.jsx in react app

I'm new to react and i started an app using create react app.When i try to rename index.js to index.jsx, I'm getting an error saying "Module build failed: Error: ENOENT: no such file or directory, open '/home/qbuser/Desktop/onChat-final/new/chat/client/src/index.js'".我是 React 新手,我使用 create react app 启动了一个应用程序。当我尝试将 index.js 重命名为 index.jsx 时,我收到一条错误消息“模块构建失败:错误:ENOENT:没有这样的文件或目录,打开“/home/qbuser/Desktop/onChat-final/new/chat/client/src/index.js”。 What should be done?应该做什么? Where did I go wrong?我哪里做错了?

It's a bug with create-react-app dev server: it can't handle renaming of index.js to index.jsx and vice versa.这是 create-react-app 开发服务器的一个错误:它无法处理 index.js 到 index.jsx 的重命名,反之亦然。 Just restart your dev server只需重新启动您的开发服务器

You need to restart the app after renaming.重命名后需要重启应用。 I fail to find a reason for this but the solution works.我找不到原因,但解决方案有效。

  1. Stop your app by pressing Ctrl + C .Ctrl + C停止您的应用程序。
  2. Then restart the app with npm start .然后使用npm start重启应用程序。

I'm new to react and i started an app using create react app.When i try to rename index.js to index.jsx, I'm getting an error saying "Module build failed: Error: ENOENT: no such file or directory, open '/home/qbuser/Desktop/onChat-final/new/chat/client/src/index.js'".我刚开始反应,我使用 create react app 启动了一个应用程序。当我尝试将 index.js 重命名为 index.jsx 时,我收到一条错误消息:“模块构建失败:错误:ENOENT:没有这样的文件或目录,打开'/home/qbuser/Desktop/onChat-final/new/chat/client/src/index.js'”。 What should be done?应该做什么? Where did I go wrong?我哪里做错了?

Rename it back to index.js.将其重命名回 index.js。 The file can still contain JSX.该文件仍然可以包含 JSX。

Or run "eject"/ use WebPack, then you can customize anything.或者运行“弹出”/使用 WebPack,然后你可以自定义任何东西。

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

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