I have a create-react-app
app and I am translation files from jsx
to typescript
. For example, one file is called /code/app_react/src/common/Action.jsx
and I renamed it to /code/app_react/src/common/Action.tsx
. I made the necessary changes to successfully convert it to tsx
, but I am getting an error related to the name change:
我有一个创建-反应-应用程序,我正在翻译文件从JSX到打字。例如,有一个文件名为/code/app_react/src/Common/Action.jsx,我将其重命名为/code/app_act/src/Common/Action.tsx。我进行了必要的更改以成功将其转换为TSX,但收到与名称更改相关的错误:
./src/common/Action.jsx Error: ENOENT: no such file or
directory, open
'/code/src/common/Action.jsx'
- rebuilding the does not help
- for some reason, the old version of the file is expected
The file importing this file is a jsx
file, but now I am importing a tsx
file into it.
导入此文件的文件是一个jsx文件,但现在我正在导入一个tsx文件。
This is a CRA app, so is there a correct way to clear this error?
这是一个CRA应用程序,那么有没有正确的方法来清除这个错误呢?
SOLUTION:
I had to remove them from the git
repository, using the git rm
command, like this:
解决方案:我必须使用git rm命令从git存储库中删除它们,如下所示:
git rm /code/src/common/Action.jsx
Once I did that, it removed the jsx
from the committed files and then I was able to use the new tsx
files
一旦我这样做了,它就从提交的文件中删除了jsx,然后我就可以使用新的tsx文件了
更多回答
did you import the file? import Action from '/code/app_react/src/common/Action.tsx'
您导入文件了吗?从‘/code/app_react/src/Common/Action.tsx’导入操作
Yes, this works perfectly fine when the extension is jsx
是的,当扩展名为JSX时,这完全可以正常工作
I have this issue as well. I'm importing the file without extension, and after an extension change I always get ENOENT and have to restart dev server. Very frustrating since that script is soooo slow to start. I will try to import with explicit extension after rename and see if that solves it.
我也有这个问题。我正在导入不带扩展名的文件,在扩展名更改之后,我总是得到ENOENT,并且必须重新启动dev服务器。非常令人沮丧,因为这个脚本启动起来太慢了。我将尝试在重命名后使用显式扩展名导入,看看这是否解决了问题。
@thehme Did you find the solution for this issue?
@thehme你找到这个问题的解决方案了吗?
yes, i had to run git rm /code/src/common/Action.jsx
是的,我必须运行git rm/code/src/Common/Action.jsx
Killed my yarn process running, killed vscode, re-started both and it works
终止了我正在运行的纱线进程,终止了vscode,重新启动了两者,并且它起作用了
I had same issue, no need to remove node_modules
or remove target file, you just have to kill the node process.
我也有同样的问题,不需要删除NODE_MODULES或删除目标文件,只需终止节点进程即可。
If you're on windows
:
如果您使用的是Windows操作系统:
- ctrl+alt+delete to run task manager
- find
node
- end process
If you're on linux
:
如果您使用的是Linux:
- probably something like
pkill node
, etc.
After I killed the node
process and ran npm start
again, it finds the target file.
在我终止节点进程并再次运行NPM Start之后,它会找到目标文件。
I was having this problem (though I had renamed js
to jsx
, rather than jsx
to tsx
), and the solution added to the question (running git rm
on the original file) didn't work for me.
我遇到了这个问题(尽管我已经将js重命名为JSX,而不是将JSX重命名为TSX),并且添加到问题中的解决方案(在原始文件上运行git rm)对我不起作用。
What did work was suggested by this r/reactjs Reddit thread: deleting and reinstalling node_modules
:
这条r/reactjs Reddit线程建议了什么方法起作用了:删除并重新安装node_MODULES:
rm -rf node_modules && npm i
It is happening because of the pre-built cache. A simple solution would be to restart your nodejs and react app.
这要归功于预置的高速缓存。一个简单的解决方案是重启NodeJS并反应应用程序。
In Linux
在Linux中
$ pkill node
$ killall node
$ kill -9 <pid>
In Windows
在Windows中
C:\>taskkill /im node.exe
C:\>taskkill /f /im node.exe
C:\>taskkill /pid <PID of node>
In MacOs
在MacOS中
$sudo killall -9 node
And then start your React application again.
然后再次启动您的Reaction应用程序。
npm start
Maybe you have not imported the file. You need to import the file to use it.
可能您尚未导入该文件。您需要导入文件才能使用它。
import Action from '/code/app_react/src/common/Action.tsx';
Also add this to your webpack.config.js.
还要将此代码添加到您的webpack.config.js中。
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"]
},
You're good to go!
你可以走了!
I had the same issue converting .jsx to .tsx. If you're using Parcel to build your app, delete the .cache
folder. That's where Parcel caches build files. That fixed it for me.
我在将.jsx转换为.tsx时遇到了同样的问题。如果您正在使用Parcel构建您的应用程序,请删除.cache文件夹。这就是Parcel缓存构建文件的位置。这就帮我修好了。
I was working with redux and then came across this error!!
我正在使用redux,然后遇到了这个错误!!
I tried killing node , removing node modules, restarting the laptop but it still gave the same error then later I started debugging index.js
我尝试终止节点、删除节点模块、重新启动笔记本电脑,但仍然出现相同的错误,然后我开始调试index.js
I commented each line and started uncommenting from top to see where the code is breaking then observed
我注释了每一行,并从顶部开始取消注释,以查看代码在哪里出错,然后观察
I had not installed
redux
I had only installed react-redux
Just restart your npm server, it will automatically detect the typescript file and make adjustments
只需重新启动您的NPM服务器,它会自动检测打字文件并进行调整
It took me all day and all I needed was to restart docker :)
And I do need to restart it after every file change to tsx.
这花了我一整天的时间,我所需要的就是重新启动docker:),而且我确实需要在每次更改TSX文件后重新启动它。
If you are in parent folder or other folder not current folder then you got this error.
Just go that directory, by using command
如果您位于父文件夹或其他文件夹中,而不是当前文件夹,则会出现此错误。只需使用以下命令转到该目录
cd folder-name
npm start
it will work
看起来不错
npm run build
NPM运行版本
try running this command
尝试运行此命令
After giving npm start I was getting this error : Error: ENOENT: no such file or directory, open 'C:\React\client.next\BUILD_ID']
在执行NPM启动后,我收到此错误:ERROR:ENOENT:没有这样的文件或目录,请打开‘C:\REACT\CLIENT.NEXT\Build_ID’]
Try rebuilding your Next.js project. You can do this by running the following command from your project's root directory:
npm run build
尝试重新构建您的Next.js项目。您可以通过从项目的根目录运行以下命令来完成此操作:npm run Build
This fixed my error and after giving npm start everything is working fine
这修复了我的错误,在给NPM启动后,一切都运行正常
I manually deleted the node_modules
folder and re-installed them by running npm i
and the trick worked for me.
我手动删除了NODE_MODULES文件夹,并通过运行npm I重新安装了它们,这个技巧对我起作用了。
A simple server restart works.
一次简单的服务器重启就可以了。
Eg: NPM RUN DEV or any start script worked for me
例句:NPM Run DEV或任何开始脚本都适合我
I also had the problem in a React Application (started with yarn start and displayed at localhost:3000). The problem arised after renaming a component and forgetting the suffix .js. After adding the suffix .js the already started App still was searching for the file without the suffix. The solution was similar to Umanda's recommendation:
我在一个Reaction应用程序中也遇到了这个问题(从Snow Start开始,显示在Localhost:3000)。在重命名组件并忘记后缀.js之后,出现了问题。在添加后缀.js之后,已经启动的应用程序仍然在搜索没有后缀的文件。解决方案与乌曼达的建议类似:
Ctrl-C
Ctrl-C
yarn start
纱线起点
Then the App worked.
然后,这款应用程序就起作用了。
I get the same problem when I try to run my next js apps, to fix this I just delete .next
folder that contains cache files and it works!
当我尝试运行我的下一个js应用程序时,我得到了同样的问题,为了解决这个问题,我只需删除包含缓存文件的.Next文件夹,它就起作用了!
I think for create-react-app
you need to restart the server
我认为对于创建-反应-应用程序,您需要重新启动服务器
更多回答
how to kill yarn process? Is there any command for this? Finding for ubuntu
如何杀死纱线过程?对此有什么命令吗?为ubuntu查找
A simple server restart works...
简单的服务器重启起作用了.
Thanks! This worked for me. After reloading VS code it displayed the tsconfig.json file & the issues were resolved.
谢谢!这对我很管用。在重新加载VS代码之后,它显示了tsconfig.json文件&问题已经解决。
Do we really need to restart react-scripts
everytime we remove or move a file? I am tired of waiting 1 minute for react-scripts
to boot up and compile my project :/
我们真的需要在每次删除或移动文件时重新启动反应脚本吗?我厌倦了等待1分钟的反应脚本启动并编译我的项目:/
Not need to every time but if you have cache issue, sometimes restarting and cache invalidation would help.
不是每次都需要,但如果您有缓存问题,有时重新启动和缓存失效会有所帮助。
restarting the server solved my issue, as simple as that
重新启动服务器解决了我的问题,就这么简单
There is no webpack.config.js
in an app created with create-react-app
. Unless you eject or use react-rewired or some such tool.
使用Create-Reaction-app创建的应用程序中没有webpack.config.js。除非你弹出或使用Reaction-Rewire或类似的工具。
我是一名优秀的程序员,十分优秀!