【Umi 四】 Cannot find module 'umi'
1、前序
安装完成 @umijs/preset-react,且配置好config.js之后,重新启动项目,报错 Cannot find module 'umi'
// package.json { "name": "myumi2", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "umi dev", "build": "umi build" }, "author": "", "license": "ISC", "dependencies": { "antd": "^4.7.3", "umi": "^3.2.24" }, "devDependencies": { "@umijs/preset-react": "^1.6.15" } }
// config/config.js export default { antd: {} }
2、问题
Cannot find module 'umi'
已经全局安装过 umi ,但是还是报错
3、解决方案
在当前目录下执行 yarn add umi 或 npm i umi
(一般情况下,包管理器只在当前目录下的 node_modules 文件夹下查找所依赖的库,如果文件夹下没有,也不会去系统全局查找。)
4、修改后
// package.json { "name": "myumi2", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "umi dev", "build": "umi build" }, "author": "", "license": "ISC", "dependencies": { "antd": "^4.7.3", "umi": "^3.2.24" }, "devDependencies": { "@umijs/preset-react": "^1.6.15" } }