我有一个带有 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 中产生语法错误?我只在项目的那个文件中看到这个错误。
最佳答案
您在 .map
文件中遇到错误。这些文件用于将源代码行映射到编译行。调整您传递给 Mocha 的 glob 模式,使其不会尝试将 .map
文件作为测试文件加载。像这样的东西:
mocha 'test/integration/**/*.js' --recursive
它只会加载.js
文件而不是.map
文件。我建议放置单引号以保护模式不被您的 shell 扩展。您希望模式按原样传递给 Mocha 而不是由 shell 解释。
关于javascript - 什么会导致 typescript 输出的 map 文件中出现意外标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46496223/