Search code examples
javascripttypescriptamdvisual-studio-code

VS Code cannot find module in my Typescript project


My project is a Typescript project with a browser part and a server part. Because of that, I need to have two separate tsconfig.json in order to build the browser library and the server process using node. I am using Visual Studio Code.

The project

Here is the folder structure:

myproject
 |
 +-src
 |  |
 |  +-server
 |  |  |
 |  |  +-server.ts
 |  |  +-<several-ts-files>
 |  |  +-tsconfig.ts
 |  +-main.ts
 |  +-<several-ts-files>
 |  +-disposable.ts
 |  +-tsconfig.ts
 +-out

When building the server, I will go: tsc --project src\server, when building the client, I will go: tsc --project src.

The problem

In one of my files: src\main.ts, I have the following:

import disposable = require('./disposable.ts');

export module Browser {
  export class MyClass implements disposable.Disposable {
    // Stuff
  }
}

Since the browser side part uses AMD, I am specifying it in src/tsconfig.json: "module": "amd"! Visual Studio Code marks './disposable.ts' inside the require with a red line with error:

Cannot find module './disposable.ts'

Questions

  1. Is this two tsconfig.json approach wrong?
  2. Why can't Code find my modules?

Can it be...

I remember once somebody told me that Code needs a tsconfig.json file to understand how the developer wants to build the code. However when we have two and they are not in the root? Do all editors behave like that?


Solution

  • './disposable.ts'

    Should be './disposable' i.e. drop the .ts extension.