TypeScript - Visual Studio 2015 Intellisense cannot find module

I am having problems with TypeScript intellisense in Visual Studio 2015. The problem came when I tried to switch from Nuget typing to installing them using npm. I have everything I need in node_modules/@types

but intellisense doesn't find typing saying it can't resolve the module. The project builds without errors, both using the Visual Studio build and with tsc from the command line.

My final guess is that the problem is with the version of TypeScript I am using versus the version that is typical, as the files are typed with intellisense errors when I open them. For example, I set up typing (v. ^ 15.0.21) for React (v. ^ 15.4.2) using npm. When I open the installed index.d.ts file, I get 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:

  • Unable to compile modules if "-module" flag is not specified ... (all first line)

  • A claim or expression is pending. (second line, when exporting)

  • The name "as" could not be found. (down below)
  • ';' expected. (in namespace)

You get the idea that they continue through the file. To solve the problem, I tried the following:

  • Switch to use tsconfig file instead of VS TypeScript.
  • Have 3 colleagues on computers (to work with two intellisense, the third one faced the same problem)
  • Clearing intellisense cache by deleting .suo file
  • Updates to TypeScript tools and Visual Studio. When I started, I was running a very old version of TypeScript in VS2015 Update 1. Now I am using TypeScript 2.2.2 to update VS2015 3. I checked the TypeScript version from the developer command line and the Package Manager Console.
  • Manually adds a tag ///<reference />

    pointing to the typing files. Doing this successfully resolves tsx html elements like tags <div>

    to a type JSX.IntrinsicElements

    , but the React module still doesn't resolve, likely due to the errors listed above.
  • Using an element typeroots

    in tsconfig to point directly to the @types folder. I have since removed this on the recommendation of a colleague, one of two whose intellisense worked.
  • Editing .csproj 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 root of the site and the file package.json

is in a named __Redesign

folder along with the folder node_modules

. This is why I thought that I might need to tell the compiler to type explicitly in tsconfig.

At this point, I end up trying to chase and all new ideas are appreciated. Thank.

+3


source to share


1 answer


After some experimentation, I tried to run a repair of the TypeScript 2.2.2 installer that I downloaded earlier and that fixed the problem. I'm not sure what he did to fix this problem, but at least it works.



+2


source







All Articles