Create-react-app returns “Cannot find module 'rxjs'”

风流意气都作罢 提交于 2021-01-29 09:28:51

问题


I've just installed NodeJS and NPM in a new machine. I added rxjs package in all my existing projects in order to make then start properly. However, when I run create-react-app - using npm globally or npx - I receive "Error: Cannot find module 'rxjs' ". Seems like rxjs is a new dependency of something (considering it's affecting old projects too).

I have already changed Node version to 8, 10 and 12. Reinstalled NPM, changed CRA version to 2.x.x and the trouble persists.

How can I use CRA without this problem?


回答1:


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:

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.

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. This leads me to think that this problem is almost certainly caused by sth local to you rather than sth wrong with CRA. I assume that you have searched through their issues on 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. Then run:

macOS

brew install yarn

yarn create react-app my-app

Windows (with Chocolatey)

choco install yarn

yarn create react-app my-app

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



来源:https://stackoverflow.com/questions/55994434/create-react-app-returns-cannot-find-module-rxjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!