查看: 88|回复: 0

typescript 报错:Cannot find name 'Map'

[复制链接]

1

主题

0

回帖

0

积分

积极分子

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2010-2-12
发表于 2023-2-27 15:32:00 | 显示全部楼层 |阅读模式

问题

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,修改其中的 targetlib,结果无效。

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

  • 【已解决】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.jsonincludeexclude,仍然无效。

解决

方法一(推荐):npm i @types/node -D

方法二:编译单个文件

tsc --target es6 --module commonjs fileName.ts

或者

tsc --lib es2015 fileName.ts

总结

搜索还是要靠 StackOverflow,除了高赞答案,看看排名第二三的答案。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部