Skip to content

@types issue question #246

Closed
Closed

Description

@paulsouche

Hi,

I had an issue compiling mocha unit test with ts-node as it could not find the mocha d.ts in @types. Do I really have to import mocha this way to have describe, it ... declared ?

import * as mocha from 'mocha';

Normally it should load the d.ts automatically as not excluded in tsconfig. Or am I missing something ?

Error

node_modules\ts-node\dist\index.js:160 throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset)); ^ TSError: ⨯ Unable to compile TypeScript test\test.ts (7,1): Cannot find name 'describe'. (2304) test\test.ts (10,3): Cannot find name 'beforeEach'. (2304) test\test.ts (12,3): Cannot find name 'it'. (2304) npm ERR! Test failed. See above for more details.

node 7.2.0

package.json

{
  "scripts": {
    "test": "nyc mocha --recursive --compilers ts:ts-node/register"
  },
  "devDependencies": {
    "@types/chai": "^3.4.34",
    "@types/mocha": "^2.2.33",
    "chai": "^3.5.0",
    "mocha": "^3.2.0",
    "nyc": "^10.0.0",
    "ts-node": "^1.7.0",
    "typescript": "^2.0.10"
  },
  "nyc": {
    "include": [
      "src/**/*.ts"
    ],
    "exclude": [
      "node_modules",
      "build"
    ],
    "extension": [
      ".ts"
    ],
    "require": [
      "ts-node/register"
    ],
    "reporter": [
      "json",
      "html"
    ],
    "all": true,
    "sourceMap": true
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "noImplicitAny": true,
    "strictNullChecks": true,
    "outDir": "build",
    "sourceMap": true
  },
  "exclude": [
    "node_modules",
    "build"
  ]
}

Btw thanks a lot for the great work !

Activity

  1. blakeembrey commented on Dec 7, 2016

    @blakeembrey
    Member

    Please see the existing issue, thanks. If you manage to find the issue, that would be useful, but so far it seems related to Windows and is probably a path issue with TypeScript.

  2. paulsouche commented on Dec 7, 2016

    @paulsouche
    Author

    Ok I found it ! I had to

    /// <reference types="mocha" />

    To declare mocha as ambient.

    I do not understand of which existing issue you're talking about ? But mine can be closed now.

    Thanks anyway

  3. blakeembrey commented on Dec 7, 2016

    @blakeembrey
    Member

    Try #168 or #216.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions