microsoft / TypeScript-Sublime-Plugin

IO wrapper around TypeScript language services, allowing for easy consumption by editor plugins
Apache License 2.0
1.72k stars 237 forks source link

Tests folder reports "Cannot find module" errors #706

Open pronebird opened 5 years ago

pronebird commented 5 years ago

Hi,

I have my sources under src/*.ts and tests under test/*.spec.ts. Everything works fine except for the tests where some of modules are marked with error: Cannot find module X.

How do you fight this issue?

DanielRosenwasser commented 5 years ago

Is this something that running tsc produces as well? If so, it sounds like you have a misconfigured project. In that case, StackOverflow might be a better venue.

pronebird commented 5 years ago

@DanielRosenwasser tests run using ts-node so I think that the tsconfig.json is correct.

justaskz commented 4 years ago

I ran into a similar issue. My demo project is compiling without errors, however Sublime is marking that module can not be found:

Screenshot 2019-11-21 at 01 06 19

Here is the code: https://github.com/justaskz/ts-demo Sublime Version 3.2.1, Build 3207 Typescript version: 3.7.2 Node version: 13.1.0

drakuno commented 3 years ago

I believe I am facing the same or a similar issue.

I am working in a project with a typical npm structure:

package.json
tsconfig.json
webpack.config.js
src/
|-components/
  |-header
    |-header.ts
|-services
  |-i18n
    |-core.ts
    |-index.ts

My tsconfig.json looks like this:

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./",
    "downlevelIteration": true,
    "module": "es6",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "strictBindCallApply": true,
    "target": "es6"
  },
  "files": [
    "src/index.ts"
  ]
}

My header.ts file has the following import:

import { targetsService } from "/src/services/i18n";

All of my code compiles fine; however, the Typescript plugin complains with:

Cannot find module '/src/services/i18n'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

I also see no effect from strictBindCallApply, for instance. In general, it seems like the Typescript plugin is not detecting my tsconfig.json.

Again, running tsc compiles just fine.

EDIT: I am on MacOS Mojave 10.14.6 (18G6042) running Sublime Text 3 v3.2.2 Build 3211

DavidHe1127 commented 3 years ago

Try include? "include": ["./src/**/*.ts"]