-
在使用
ts-node运行ts文件时出现问题 -
test.ts文件:tsconst arr: Object[] = [{}, 1]; const arr1: Array<Object> = [{}, 1, 2]; console.log(arr, arr1); -
执行 :
ts-node ./test.ts
-
报错 :
phperror TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. 2 console.log(arr, arr1); ~~~~~~~ at createTSError (C:\Users\ASUS\Desktop\crm\ydemo\node_modules\ts-node\src\index.ts:820:12) at reportTSError (C:\Users\ASUS\Desktop\crm\ydemo\node_modules\ts-node\src\index.ts:824:19) at getOutput (C:\Users\ASUS\Desktop\crm\ydemo\node_modules\ts-node\src\index.ts:1014:36) at Object.compile (C:\Users\ASUS\Desktop\crm\ydemo\node_modules\ts-node\src\index.ts:1322:43) at Module.m._compile (C:\Users\ASUS\Desktop\crm\ydemo\node_modules\ts-node\src\index.ts:1454:30) at Module._extensions..js (internal/modules/cjs/loader.js:1157:10) at Object.require.extensions.<computed> [as .ts] (C:\Users\ASUS\Desktop\crm\ydemo\node_modules\ts-node\src\index.ts:1458:12) -
原因 :
console不属于ECMAScript标准。DOM里面的console是浏览器环境下的(是window对象里面的),属于浏览器BOM API,Node里面的console是NodeJS里面的,由NodeJS自己定义的API,两者虽然由同样的功能,但是并不是同一个东西; -
解决 :
- 安装插件:
npm i -D tslib @types/node
- 该命令是安装
TypScript助手的运行时库,包含所有TypeScript辅助函数;
- 安装插件:
TS踩坑日记 - error TS2584: Cannot find name ‘console‘. Do you need to change your ……
禁止摆烂_才浅2023-10-16 10:26
相关推荐
董员外10 小时前
LangChain.js 快速上手指南:Tool的使用,给大模型安上了双手用泥种荷花10 小时前
【LangChain.js学习】 RAG(检索增强生成)完整实现解析兔子零102411 小时前
Star-Office-UI-Node 实战:从 0 到 1 接入 OpenClaw 的多 Agent 看板helloweilei11 小时前
一文搞懂Nextjs中的Proxywuhen_n11 小时前
Pinia状态管理原理:从响应式核心到源码实现陆枫Larry11 小时前
小程序 scroll-view 设置 padding 右侧不生效?用一层包裹解决晴殇i12 小时前
CommonJS 与 ES6 模块引入的区别详解Selicens12 小时前
git批量删除本地多余分支wuhen_n12 小时前
KeepAlive:组件缓存实现深度解析前端付豪12 小时前
Nest 项目小实践之图书展示和搜索