Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript - Visual Studio 2015 Intellisense Cannot Find Module

I am having trouble with TypeScript intellisense in Visual Studio 2015. The problem began when I attempted to switch from typings on Nuget to installing them using npm. I have everything I need in node_modules/@types but intellisense does not find the typings, saying that it cannot resolve the module. The project builds without errors, both using Visual Studio's build and tsc from a command line.

My current guess is that the issue lies in the version of TypeScript I'm using versus the version the typings are for as there are intellisense errors in the typings files when I open them up. For example, I have installed typings(v. ^15.0.21) for React(v. ^15.4.2) using npm. When I open the installed index.d.ts file, I receive numerous errors:

// Type definitions for React v15.0
// Project: http://facebook.github.io/react/
// Definitions by: ...
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2

export = React;
export as namespace React;

In these first two lines for example I get:

  • Cannot compile modules unless the '--module' flag is provided... (entire first line)

  • Declaration or statement expected. (second line, under export)

  • Cannot find name 'as'. (under as)
  • ';' expected. (under namespace)

You get the idea, these continue through the file. I have tried the following to resolve the issue:

  • Switching to using a tsconfig file rather than VS typescript tools.
  • Having 3 colleagues try on their computers (for two intellisense worked, the third encountered the same problem)
  • Clearing the intellisense cache by deleting the .suo file
  • Updating TypeScript tools and Visual Studio. When I started I was running a very old version of TypeScript on VS2015 Update 1. I am now using TypeScript 2.2.2 on VS2015 Update 3. I have verified the version of TypeScript from the developer command prompt and the package manager console.
  • Manually adding a ///<reference /> tag pointing to the typings files. Doing this successfully resolves tsx html elements, such as <div> tags to the JSX.IntrinsicElements type but the React module still does not resolve, likely because of the errors listed above.
  • Using a typeroots element in the tsconfig to point directly to the @types folder. I have since removed this at the recommendation of a colleague, one of the two whose intellisense worked.
  • Editing the .csproj file TypeScript sections. I changed the TypeScript tools version to 2.2, and the module resolution option to Node, node, and NodeJs as suggested here: https://github.com/Microsoft/TypeScript/issues/7568

Here is my tsconfig.json file:

{
    "compileOnSave": true,
    "compilerOptions": {
        "sourceMap": true,
        "noImplicitAny": false,
         "module": "commonjs",
         "target": "es5",
         "jsx": "react"
    },
    "exclude": [ "./__Redesign/node_modules", "./__Redesign/jspm_packages" ],
    "include": [
        "./__Redesign/node_modules/@types",
        "__Redesign/app/**/*.ts",
        "__Redesign/app/**/*.tsx"
    ]
}

My tsconfig is in the site root and the package.json file is in a folder called __Redesign along with the node_modules folder. This is why I thought I might need to point the compiler to the typings explicitly in the tsconfig.

At this point I'm running out of leads to chase down and any new ideas are appreciated. Thanks.

like image 575
ScoobyDrew18 Avatar asked Oct 29 '22 09:10

ScoobyDrew18


1 Answers

After a little more experimenting I tried running a repair on the TypeScript 2.2.2 installer I downloaded earlier and this fixed the problem. I'm not sure what it did to fix the problem, but at least it's working.

like image 115
ScoobyDrew18 Avatar answered Nov 20 '22 16:11

ScoobyDrew18