问题
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