Definitelytyped: Error on chai types

Created on 29 Aug 2017  ·  3Comments  ·  Source: DefinitelyTyped/DefinitelyTyped

Hi, I am resonably new to typescript and mocha/chai in general. I am trying to replicate my work configuration (Windows 8) on my home computer (Windows 10) and I get the following error from the compiler (at work all works fine):

C:\dev\bookapi\mocha-api-test>tsc
node_modules/@types/chai/index.d.ts(1244,15): error TS2451: Cannot redeclare block-scoped variable 'chai'.
test/get-books-200ok.test.ts(24,5): error TS2451: Cannot redeclare block-scoped variable 'chai'.

This is my package.json:
{
"name": "mocha-api-test",
"version": "1.0.0",
"private": true,
"description": "BookAPI",
"scripts": {
"test": "mocha --reporter mocha-junit-reporter -r ts-node/register test/*/.test.ts"
},
"license": "ISC",
"dependencies": {
"@types/chai": "^3.4.35",
"@types/chai-http": "0.0.30",
"@types/chai-json-schema": "^1.4.2",
"@types/mocha": "^2.2.39",
"@types/node": "^7.0.5",
"chai": "^3.5.0",
"chai-http": "^3.0.0",
"chai-json-schema": "^1.4.0",
"mocha": "^3.2.0",
"mocha-junit-reporter": "^1.13.0",
"ts-node": "^3.1.0",
"typescript": "^2.4.1"
}
}

and this is the tsconfig.ts:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": false,
"outDir": "./build",
"typeRoots": [
"node_modules/@types"
],
"types": [
"mocha",
"node",
"chai",
"chai-http",
"chai-json-schema"
]
},
"exclude": [
"node_modules",
"build"
]
}

Thanks for any help

All 3 comments

found the solutions thanks anyway.. can be closed

could you please tell me the fix for this error?

If anyone has this problem, double-check if you're not importing ts-node multiple times. In my case, I was importing it in command (mocha -r ts-node/register) and in mocha.opts (--require ts-node/register).

Was this page helpful?
0 / 5 - 0 ratings