typescript 报错:Cannot find name 'Map'
问题
error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.
typescript 默认使用 ES5,不支持 ES6.
尝试
根据以下链接,tsc -init 生成 tsconfig.json,修改其中的 target 、lib,结果无效。
-
Cannot find name ‘XX‘. Do you need to change your target library? Try changing the
libcompiler -
【已解决】Cannot find name ‘Set‘. Do you need to change your target library?
-
Cannot find name ‘Map‘. Do you need to change your target library? Try changing the ‘lib‘ compiler o
根据 StackOverflow 上修改 tsconfig.json 的 include 和 exclude,仍然无效。
解决
方法一(推荐):npm i @types/node -D
方法二:编译单个文件
tsc --target es6 --module commonjs fileName.ts
或者
tsc --lib es2015 fileName.ts
总结
搜索还是要靠 StackOverflow,除了高赞答案,看看排名第二三的答案。
本文来自博客园,作者:shayloyuki,转载请注明原文链接:https://www.cnblogs.com/shayloyuki/p/17159883.html
posted on 2023-02-27 15:32 shayloyuki 阅读(2137) 评论(0) 收藏 举报
浙公网安备 33010602011771号