美文网首页
Cannot find name ‘XX‘. Do you ne

Cannot find name ‘XX‘. Do you ne

作者: 天渺工作室 | 来源:发表于2021-05-08 17:05 被阅读0次

    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
    
    image.gif

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

    请执行

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

    将tsconfig.json中的配置项

    "target": "es5",   改成 "target": "es6", 
    
    image.gif

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

    相关文章

      网友评论

          本文标题:Cannot find name ‘XX‘. Do you ne

          本文链接:https://www.haomeiwen.com/subject/cmoudltx.html