javascript - 什么会导致 typescript 输出的 map 文件中出现意外标记?

标签 javascript typescript mocha.js tsconfig

我有一个带有 tsconfig.json

的 typescript 项目
{
    "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 中产生语法错误?我只在项目的那个文件中看到这个错误。

最佳答案

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

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

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

关于javascript - 什么会导致 typescript 输出的 map 文件中出现意外标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46496223/

相关文章:

javascript - Elm 中的无限滚动

javascript - jQuery - 填充对象中缺失的星期几值

typescript - 替换 Typescript 包上的 'require'

reactjs - Mocha 不会识别 JSX

javascript - jquery选择的链接激活但不同的div

javascript - 使用Web Worker的最大HTTP请求数

javascript - 使用 Object.entries 时保留类型

node.js - 如何修复找不到模块 'fs'

automated-tests - 在服务器上运行带有Mocha的NightmareJS(Bamboo代理)

javascript - 我可以通过 Mocha 运行 Jasmine 测试吗