尝试按照官方手册实现模块,我收到以下错误消息:
未捕获的ReferenceError:未定义导出
在app.js:2
但我的代码中没有任何地方使用该名称exports.
我怎样才能解决这个问题?
let a = 2;
let b:number = 3;
import Person = require ('./mods/module-1');
Run Code Online (Sandbox Code Playgroud)
export class Person {
constructor(){
console.log('Person Class');
}
}
export default Person;
Run Code Online (Sandbox Code Playgroud)
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"sourceMap": true,
"outDir": "scripts/"
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud) ts 编译器在每个文件中发出这一行:
Object.defineProperty(exports, "__esModule", { value: true });
Run Code Online (Sandbox Code Playgroud)
但是我的代码在 Nodejs 上运行,我没有编写 libaray,所以我认为这行代码对我来说是不必要的。我怎样才能禁用它?我的编译器选项是:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"allowJs": true,
"sourceMap": true,
"outDir": "build",
"moduleResolution": "Node",
"lib": ["es6"]
}
}
Run Code Online (Sandbox Code Playgroud)
例如,编译这个 ts 文件:
function add(a: number, b: number): number {
return a + b
}
export { add }
Run Code Online (Sandbox Code Playgroud)
我有:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function add(a, b) {
return a + b;
}
exports.add = add;
//# sourceMappingURL=App.js.map
Run Code Online (Sandbox Code Playgroud)
如何删除第二行?