Cannot find name ‘XX‘. Do you need to change your target library? Try changing the `lib` compiler

typescript 在编译运行的时候或ts-node xxx.ts运行的时候 报错

不管是Set Map 还是啥其他的es6新语法编译报错

Cannot find name 'Map(编译不了的哪一项)'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2015' or later

如果当前项目没有tsconfig.json 配置文件

请执行 

//生成tsconfig.json 编译配置文件
tsc -init

将tsconfig.json中的配置项

"target": "es5", 改成 "target": "es6",

 

提示说的很清楚了,意思就是让咱修改个编译时需要引入的库,为什么会出现这种原因,是因为咱们在ts的配置里面配置target为es5时,它默认注入的库为ES5...... 显然Set,Map......(es6的那些新语法)在es5时是不存在,所以就编译失败。

posted @ 2021-05-08 17:08  天渺工作室  阅读(2102)  评论(0编辑  收藏  举报