相关疑难解决方法(0)

Typescript ReferenceError:未定义导出

尝试按照官方手册实现模块,我收到以下错误消息:

未捕获的ReferenceError:未定义导出

在app.js:2

但我的代码中没有任何地方使用该名称exports.

我怎样才能解决这个问题?


app.ts

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

import Person = require ('./mods/module-1');
Run Code Online (Sandbox Code Playgroud)

模块1.T

 export class Person {
  constructor(){
    console.log('Person Class');
  }
}
export default Person;
Run Code Online (Sandbox Code Playgroud)

tsconfig.json

{
   "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": true,
        "outDir": "scripts/"
    },
    "exclude": [
        "node_modules"
    ]
}
Run Code Online (Sandbox Code Playgroud)

module typescript

76
推荐指数
11
解决办法
13万
查看次数

未捕获的ReferenceError:在Typescript生成的字段中未定义导出

我正在尝试使用Typescript进行电子开发.在为节点和jquery打字之后,我终于得到了我的.ts文件错误.

问题是,当我运行我的应用程序时,我收到此错误:

index.js:2 Uncaught ReferenceError: exports is not defined
Run Code Online (Sandbox Code Playgroud)

这些是index.js中的前两行:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Run Code Online (Sandbox Code Playgroud)

我不知道那条线.打字稿在编译时添加了它.如果删除它,我的应用程序工作正常.

我该如何摆脱这个错误?

哦,这是我的tsconfig,如果这是相关的.

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "node",
        "isolatedModules": false,
        "jsx": "react",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": false,
        "noImplicitAny": false,
        "noImplicitUseStrict": false,
        "removeComments": true,
        "noLib": false,
        "preserveConstEnums": true,
        "suppressImplicitAnyIndexErrors": true
    },
    "exclude": [
        "node_modules",
        "typings/browser",
        "typings/browser.d.ts"
    ],
    "compileOnSave": true,
    "buildOnSave": false,
    "atom": {
        "rewriteTsconfig": false
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript typescript

20
推荐指数
5
解决办法
4万
查看次数

标签 统计

typescript ×2

javascript ×1

module ×1