我在mocha
中创建了test.ts
测试
import * as assert from "assert";
describe('it', () => {
it('should ', done => {
assert.strictEqual(true, false);
done();
});
});
我的package.json
的{{1}}:
devDependencies
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.18",
"mocha": "^5.2.0",
"ts-node": "^8.0.1",
"typescript": "^3.2.4"
}
:
tsconfig.json
运行{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"strict": true,
"types": ["mocha"]
}
}
时,出现此错误:
ts-node
我的命令行调用是这样:
error TS2307: Cannot find module 'assert'.
常规./node_modules/mocha/bin/mocha -r ts-node/register test/test.ts
不会引发错误。
答案 0 :(得分:0)
通过GitHub上的this issue comment解决了该问题:
types
中的 tsconfig.json
必须包含node
:
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"strict": true,
"types": ["mocha", "node"]
}
}