ReferenceError:找不到变量:exports

kem*_*ica 7 javascript typescript

题:

为什么我收到以下错误?我忘记在我的HTML中添加脚本了吗?

ReferenceError:找不到变量:exports

从typescript生成的javascript导致它:

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

额外:

tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "noImplicitAny": true,
    "rootDir": ".",
    "sourceRoot": "../../../",
    "outDir": "../../../js/dist/",
    "sourceMap": false
  },
  "exclude": [
    "node_modules"
  ]
}
Run Code Online (Sandbox Code Playgroud)

requirejs包含在html中的js文件之前

有类似的问题,但这只是关于打字稿而不是关于余烬/巴贝尔等.

Nic*_*lay 1

我无法重现。您的保释tsconfig.json理由tsc

错误 TS5051:仅当提供选项“--inlineSourceMap”或选项“--sourceMap”时才能使用选项“sourceRoot”。

一旦我删除该选项,输出中sourceRoot就没有任何引用。exports


$ls

my.ts       tsconfig.json
Run Code Online (Sandbox Code Playgroud)

$ 猫 my.ts

console.log(1)
Run Code Online (Sandbox Code Playgroud)

$ 猫 tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "noImplicitAny": true,
    "rootDir": ".",
    "sourceRoot": "../../../",
    "outDir": "../../../js/dist/",
    "sourceMap": false
  },
  "exclude": [
    "node_modules"
  ]
}
Run Code Online (Sandbox Code Playgroud)

$ tsc --版本

Version 3.5.3
Run Code Online (Sandbox Code Playgroud)