【问题标题】:What would cause a unexpected token in typescript outputed map file?什么会导致打字稿输出的地图文件中出现意外标记?
【发布时间】:2017-09-29 20:07:05
【问题描述】:

我有一个带有tsconfig.json 的打字稿项目

{
    "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "sourceMap": true,
    "inlineSources": true,
    "lib": [
      "es6",
      "dom"
    ],
    "types": [
      "node"
    ],
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

我正在运行一个脚本"test:integration": "./node_modules/typescript/bin/tsc && mocha test/integration/** --recursive"

然后我看到了:

/Users/mm81509/projects/coverpath-producer-management/test/integration /Example.js.map:1
(function (exports, require, module, __filename, __dirname) { {"version":3,"file":"Example.js","sourceRoot":"","sources":["Example.ts"],"names":[],"mappings":"","sourcesContent":[""]}
                                                                        ^
SyntaxError: Unexpected token :
...

什么会导致 typescript 编译器在 map.js 中产生语法错误?我只在项目的那个文件中看到这个错误。

【问题讨论】:

    标签: javascript typescript mocha.js tsconfig


    【解决方案1】:

    您在 .map 文件中遇到错误。这些文件用于将源代码行映射到编译行。调整您传递给 Mocha 的 glob 模式,使其不会尝试将 .map 文件加载为测试文件。比如:

    mocha 'test/integration/**/*.js' --recursive
    

    它只会加载.js 文件而不是.map 文件。我建议使用单引号来保护模式不被你的 shell 扩展。您希望将模式按原样传递给 Mocha,而不是由 shell 解释。

    【讨论】:

      猜你喜欢
      • 2020-10-14
      • 1970-01-01
      • 2016-01-12
      • 2020-09-14
      • 2019-09-15
      • 2021-07-09
      • 2015-02-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多