错误展示
Cannot find name 'console'. Do you need to change your target library?ging the 'lib' compiler option to include 'dom'.
2 console.log("当我唱起这首歌");
~~~~~~~
at createTSError (D:\Software\node-v14.8.0-win-x64\node-global\node_modules\ts-node\src\index.ts
at reportTSError (D:\Software\node-v14.8.0-win-x64\node-global\node_modules\ts-node\src\index.ts
at getOutput (D:\Software\node-v14.8.0-win-x64\node-global\node_modules\ts-node\src\index.ts:941
at Object.compile (D:\Software\node-v14.8.0-win-x64\node-global\node_modules\ts-node\src\index.t)
at Module.m._compile (D:\Software\node-v14.8.0-win-x64\node-global\node_modules\ts-node\src\inde:30)
at Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
at Object.require.extensions.<computed> [as .ts] (D:\Software\node-v14.8.0-win-x64\node-global\nes\ts-node\src\index.ts:1374:12)
at Module.load (internal/modules/cjs/loader.js:1100:32)
at Function.Module._load (internal/modules/cjs/loader.js:962:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
diagnosticText: "\x1B[96m01调试.ts\x1B[0m:\x1B[93m2\x1B[0m:\x1B[93m3\x1B[0m - \x1B[91merror\x1B[0m
TS2584: \x1B[0mCannot find name 'console'. Do you need to change your target library? Try changing t
compiler option to include 'dom'.\r\n" +
'\r\n' +
'\x1B[7m2\x1B[0m console.log("当我唱起这首歌");\r\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~\x1B[0m\r\n',
diagnosticCodes: [ 2584 ]
}
解决方法,只需要在终端运行一段命令即可
npm install -D tslib @types/node
该命令是安装TypeScript助手的运行时库,包含所有TypeScript辅助函数