[英]Create-react-app returns “Cannot find module 'rxjs'”
I've just installed NodeJS and NPM in a new machine. 我刚刚在一台新机器上安装了NodeJS和NPM。 I added
rxjs
package in all my existing projects in order to make then start properly. 我在所有现有项目中添加了
rxjs
包,以便正确启动。 However, when I run create-react-app
- using npm globally or npx - I receive "Error: Cannot find module 'rxjs' ". 但是,当我运行
create-react-app
- 使用npm global或npx - 我收到“错误:无法找到模块'rxjs'”。 Seems like rxjs
is a new dependency of something (considering it's affecting old projects too). 似乎
rxjs
是某种东西的新依赖(考虑到它也影响旧项目)。
I have already changed Node version to 8, 10 and 12. Reinstalled NPM, changed CRA version to 2.xx and the trouble persists. 我已经将Node版本更改为8,10和12.重新安装NPM,将CRA版本更改为2.xx并且问题仍然存在。
How can I use CRA without this problem? 如何在没有此问题的情况下使用CRA?
As mentioned by the Original Poster in the comments, the fix could be to clear your cache. 正如评论中的原始海报所述,修复可能是清除缓存。
npm cache clean --force
If this still doesn't work, you can follow the steps below to install and try with Yarn: 如果这仍然不起作用,您可以按照以下步骤安装并尝试使用Yarn:
If neither npx create-react-app my-app
and npm init react-app my-app
are working for you, try Yarn to see how it goes. 如果
npx create-react-app my-app
和npm init react-app my-app
都不适合你,试试Yarn看看它是怎么回事。
I have used CRA is multiple projects on Windows, Ubuntu, Mint and macOS and have never explicitly installed rxjs, nor have I been asked for it. 我用过CRA是Windows,Ubuntu,Mint和macOS上的多个项目,从未明确安装过rxjs,也没有被要求过。 This leads me to think that this problem is almost certainly caused by sth local to you rather than sth wrong with CRA.
这让我觉得这个问题几乎肯定是由你本地引起的,而不是CRA的错误。 I assume that you have searched through their issues on Github.
我假设您已经在Github上搜索了他们的问题。
Try it with Yarn Open a new terminal (linux and macOS) or command line (Windows) session cd'd to your documents folder or suitable alternative. 尝试使用Yarn打开一个新的终端(linux和macOS)或命令行(Windows)会话cd'd到您的文档文件夹或合适的替代方案。 Then run:
然后运行:
macOS 苹果系统
brew install yarn
yarn create react-app my-app
Windows (with Chocolatey) Windows(带巧克力)
choco install yarn
yarn create react-app my-app
Ubuntu Ubuntu的
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
yarn create react-app my-app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.