这阵子出现了一个React前端项目运行报错的问题,场景是 npm run start 报错
Cannot find type definition file for 'lodash'.
该问题尝试了网上多种方式 ,如
方案1:
npm install --save-dev @types/lodash
再配合
{
"compilerOptions": {
"typeRoots": ["node_modules/@types"],
"types": ["lodash"]
}
}
或者
方案2:
npm uninstall typescript -g
npm install typescript -g
或者
方案3:
删除重装node, 清空机器的node_modules。再重装重新 npm install , npm run start
方案4:
npm cache clean --f ,之后重新 npm intall
上述种种方案都不行。最终感觉隐隐约约可能是package.json 中什么东西版本有问题,
于是将其中的
"typescript": "^3.7.4" 升级到 "typescript": "^5.4.5"
问题终于解决。该问题出现在老项目正常运行,新项目接手后好像是升级了什么导致,但是具体原因未知,因为相关软件已经卸载重装至老版本。
问题记录:该问题处理耗时1天