反应:create-react-app失败,并显示错误“找不到模块'lodash'". [英] React: create-react-app fails with error "Cannot find module 'lodash'"

查看:241
本文介绍了反应:create-react-app失败,并显示错误“找不到模块'lodash'".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次学习React,即使开始使用演示应用程序也遇到很多麻烦.当我运行npx create-react-app时,出现以下错误:

I'm learning React for the first time, and I'm having a great deal of trouble even getting started with a demo app. When I run npx create-react-app I get the following error:

这是在Windows 10 npm/npx版本6.4.1上.我试过npm install并使用npm i -g lodash安装lodash,这告诉我已经安装了lodash 4.17.11.但是create-react-app命令仍会生成完全相同的错误消息.

This is on Windows 10, npm/npx version 6.4.1. I tried npm install and installing lodash using npm i -g lodash, which tells me lodash 4.17.11 is installed. But the create-react-app command is still generating the exact same error message.

这看起来很奇怪.我在网上四处张望,找不到与该错误有关的任何其他引用,因为它与create-react-app命令相关,并且其他答案(npm install/npm i -s lodash)的解决方案不起作用(-s要求有一个应用文件夹是在使用create-react-app之前创建的,但create-react-app要求应用文件夹完全为空).

This seems very bizarre. I've looked around online and cannot find any other references to this error as it relates to the create-react-app command, and the solutions on other answers (npm install/npm i -s lodash) are not working (-s requires that an app folder be created in advance of using create-react-app, but create-react-app requires that the app folder be completely empty).

我该如何解决此问题,以便可以开始构建我的第一个React应用并学习框架?

How do I approach resolving this problem so that I can get started with building my first react app and learning the framework?

更新-package.json

该命令正在删除package.json,但是如果我在notepad ++中打开它,则安装程序崩溃之前的最后一个版本似乎包含以下基本信息.

The package.json is being deleted by the command, but if I open it in notepad++, the last version before the installer crashes seems to contain contain the following minimal information.

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.5.2",
    "react-dom": "^16.5.2",
    "react-scripts": "2.0.3"
  }
}

安装后剩下的唯一文件似乎是package-lock.json,它非常长,只有0.6mb.如果需要,我可以将其发布在某个地方.

The only file left over after the installation seems to be a package-lock.json, which is very lengthy 0.6mb. I can post it somewhere if needed.

推荐答案

我继续寻找其他人遇到的类似问题,有人建议:

I continued searching for similar problems that others have had, and someone suggested:

npm cache clean --force 

所以我做到了,然后又做了一个:

so I did that, then I did another:

npm i 

和...

npm i -g create-react-app 

然后create-react-app命令起作用了!!

then the create-react-app command worked!!

我希望这对以后的人有所帮助.

I hope this helps someone in the future.

这篇关于反应:create-react-app失败,并显示错误“找不到模块'lodash'".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆