采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
tsc 编译后运行报错 2_demo.js:2 Uncaught ReferenceError: exports is not defined
用了export{} 就无法运行了,不用export{}就没问题,这个要怎么解决呢
TS: let foo = 45611111; console.log(foo); export {}; JS: "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); let foo = 45611111; console.log(foo);
你好,首先添加了export {} ,这表示文件为一个模块。那么默认情况下,tsconfig.json文件使用 "module": "commonjs", 作为转换后的模块,所以默认需要在nodejs环境下才能运行,即:\test> node 1demo.js 想要在前端运行可选择 "module": "ES6" ,再通过:<script src="./1demo.js" type="module"></script> + 服务器环境
感谢🙏
登录后可查看更多问答,登录/注册
专为初级前端人员设计,系统性学习三大技术
557 10
819 9
1.1k 7
961 7
8.3k 7
购课补贴联系客服咨询优惠详情
慕课网APP您的移动学习伙伴
扫描二维码关注慕课网微信公众号