Skip to content

The new @types folder for TypeScript doesn't work on VSCode #9507

Closed

Description

@brunolm
  • VSCode Version: 1.3.1
  • OS Version: Windows 10 Pro

Steps to Reproduce:

  1. npm i -D @types/mocha
  2. Create a file.ts with
describe('test', () => { })

Error: Cannot find name describe

If I build manually with TS it works.

If I do a typings install --global mocha instead of npm i -D @types/mocha then both VSCode and Webpack work correctly.

Structure

├ spec
├─ index.ts
├ src
├─ index.ts
├ tsconfig.json
├ package.json
├ webpack.config.js

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "noImplicitAny": false,
    "sourceMap": false,
    "typeRoots": ["node_modules/@types"]
  },
  "exclude": [
    "node_modules"
  ]
}

webpack.config.js

module.exports = {
  entry: {
    app: ['babel-polyfill', './src/'],
    test: ['babel-polyfill', './spec/'],
  },
  output: {
    path: __dirname,
    filename: './dist/[name].js',
  },
  resolve: {
    extensions: ['', '.js', '.ts'],
  },
  module: {
    loaders: [{
      test: /\.ts$/, loaders: ['babel-loader', 'ts-loader'], exclude: /node_modules/
    }],
  }
};

Dependencies:

  "devDependencies": {
    "@types/mocha": "^2.2.28",
    "@types/node": "^4.0.30",
    "babel-core": "^6.10.4",
    "babel-loader": "^6.2.4",
    "babel-polyfill": "^6.9.1",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-stage-0": "^6.5.0",
    "mocha": "^2.5.3",
    "rimraf": "^2.5.3",
    "ts-loader": "^0.8.2",
    "typescript": "^2.0.0",
    "webpack": "^1.13.1"
  }

Activity

  1. lukaszczernal commented on Oct 14, 2016

    @lukaszczernal

    BrunoLM (@brunolm),

    I added "typescript.tsdk": "./node_modules/typescript/lib" to my setting.json file but still get errors in VSCode console (althought the project builds without any errors).

    I'm having an issue when using Jasmin. It says it cannot find name 'describe' (same for 'it', 'expect'). If I add import {} from 'jasmine'; at the beginning of my spec file the errors disapear from VSCODE console.

    Do you might have any ideas?

    I'm using VS Code version 1.6.1 and my tsconfig.json file looks like this:

    {
      "compilerOptions": {
        "declaration": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "target": "es5",
        "noEmitHelpers": true,
        "pretty": true,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "inlineSources": true,
        "sourceMap": true,
        "outDir": "./dist",
        "rootDir": "./src",
        "typeRoots": [ "node_modules/@types" ],
        "strictNullChecks": false    
      },
      "exclude": [
        "node_modules"
      ],
      "files": [
        "src/index.ts"
      ],
      "angularCompilerOptions": {
        "strictMetadataEmit": true
      },  
      "compileOnSave": false,
      "buildOnSave": false
    }
    
  2. anilanar commented on Feb 22, 2017

    @anilanar

    This issue needs to be reopened.

  3. locked and limited conversation to collaborators on Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions