create-react-app 无法找到模块 'ajv/dist/compile/codegen'

pdsfdshx  于 22天前  发布在  React
关注(0)|答案(2)|浏览(17)

描述问题

我刚接触npm的世界。按照Getting Started页面上的说明,执行"npx create-react-app my-app; cd my-app; npm start",却收到错误信息 "Cannot find module 'ajv/dist/compile/codegen'"。

你尝试恢复依赖了吗?

我不得不手动输入npm install --save-dev ajv才能让它正常工作。我将这个问题报告为一个问题,因为这显然不是预期的行为,对于初学者来说也不太友好。如果这种情况只发生在我的机器上,那么我想了解我的环境中出了什么问题。

环境

我使用的是npm版本10.8.2
我按照推荐的"npm install -g npm@latest"进行了操作,删除了my-app目录并再次尝试,但问题仍然存在。

(dev) luc@yoga:~/work/my-app$ npm ls -g
/usr/local/lib
├── corepack@0.28.1
├── html-webpack-plugin@5.6.0
├── n@9.2.3
├── npm@10.8.2
├── react-dom@18.3.1
└── typedoc@0.25.3

环境信息:
create-react-app的当前版本:5.0.1
正在运行的路径:/home/luc/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app
系统:
操作系统:Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
CPU:(8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
二进制文件:
Node: 20.15.1 - /usr/local/bin/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
浏览器:
Chrome: Not Found
npmPackages:
react: ^18.3.1 => 18.3.1
react-dom: ^18.3.1 => 18.3.1
react-scripts: 5.0.1 => 5.0.1
npmGlobalPackages:
create-react-app: Not Found

重现问题的步骤

按照https://create-react-app.dev/docs/getting-started的说明进行操作:

npx create-react-app my-app
cd my-app
npm start

预期行为

没有错误信息,浏览器在http://localhost:3000启动。

实际行为

jum4pzuy

jum4pzuy1#

运行 npm uninstall -g create-react-app 以移除全局 create-react-app 包。然后,尝试再次使用 npx create-react-app my-app
npx 将自动下载 create-react-app 的最新版本并使用它来设置您的项目。

j2datikz

j2datikz2#

请运行 npm uninstall -g create-react-app 以移除全局 create-react-app 包。然后,尝试再次使用 npx create-react-app my-app
npx 将自动下载 create-react-app 的最新版本并用于设置您的项目。
感谢您的建议。遗憾的是,它没有帮助。
您的建议让我想到了尝试 "sudo apt remove npm" 后跟 "sudo apt install npm"。但这也没有帮助。

相关问题