gpt4 book ai didi

typescript 引用错误 : exports is not defined

转载 作者:搜寻专家 更新时间:2023-10-30 20:28:53 25 4
gpt4 key购买 nike

尝试在 official handbook 之后实现一个模块,我收到此错误消息:

Uncaught ReferenceError: exports is not defined

at app.js:2

但在我的代码中,我从未使用过名称 exports

我该如何解决这个问题?


文件

应用.ts

let a = 2;
let b:number = 3;

import Person = require ('./mods/module-1');

模块1.t

 export class Person {
constructor(){
console.log('Person Class');
}
}
export default Person;

tsconfig.json

{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"sourceMap": true,
"outDir": "scripts/"
},
"exclude": [
"node_modules"
]
}

最佳答案

在其他对 JavaScript 的引用之前添加以下行。这是一个不错的小技巧。

<script>var exports = {};</script>

关于 typescript 引用错误 : exports is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43042889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com