执行npm run dev/build时遇TypeScript TS1005错误求助
TypeScript编译失败问题解决(cheerio-select类型定义报错)
执行npm run dev或npm run build时触发TypeScript编译失败,错误详情如下:
编译失败。
/home/fislam/Documents/frontend/client-dashboard/node_modules/cheerio-select/lib/index.d.ts(1,15): 预期','。TS10051 | import { type Options as CSSSelectOptions } from "css-select";
| ^
解决方法
升级TypeScript版本
该错误是因为当前TS版本不支持import { type XXX }这种简写类型导入语法(需TypeScript 4.5及以上版本支持)。先查看当前TS版本:tsc -v若版本低于4.5,执行升级命令:
npm install typescript@^4.5 --save-dev降级cheerio-select版本
若暂时无法升级TS,可安装兼容旧版TS的cheerio-select版本:npm install cheerio-select@^1.5.0 --save临时修改类型定义文件(不推荐)
直接修改node_modules/cheerio-select/lib/index.d.ts第1行,将语法改为旧版TS支持的写法:import type { Options as CSSSelectOptions } from "css-select";注意:此修改会在执行
npm install后被覆盖,仅作临时应急使用。
内容的提问来源于stack exchange,提问作者GCT
相关产品推荐
相关产品推荐

