tsc throws `TS2307: Cannot find module` for a local file

angular error ts2307: cannot find module
typescript cannot find module
semantic error ts2307: cannot find module
ts2307: cannot find module 'vue
ts2307 cannot find module image
ts2307 cannot find module '@angular/core'
error ts2307: cannot find module '@angular 7
ts2307: cannot find module 'react

I've got a simple example project using TypeScript: https://github.com/unindented/ts-webpack-example

Running tsc -p . (with tsc version 1.8.10) throws the following:

app/index.ts(1,21): error TS2307: Cannot find module 'components/counter'.
components/button/index.ts(2,22): error TS2307: Cannot find module 'shared/backbone_base_view'.
components/button/index.ts(3,25): error TS2307: Cannot find module 'shared/backbone_with_default_render'.
components/counter/index.ts(2,22): error TS2307: Cannot find module 'shared/backbone_base_view'.
components/counter/index.ts(3,25): error TS2307: Cannot find module 'shared/backbone_with_default_render'.
components/counter/index.ts(4,27): error TS2307: Cannot find module 'shared/backbone_with_subviews'.
components/counter/index.ts(5,20): error TS2307: Cannot find module 'components/button'.

It complains about all imports of local files, like the following:

import Counter from 'components/counter';

If I change it to a relative path it works, but I don't want to, as it makes my life more difficult when moving files around:

import Counter from '../components/counter';

The vscode codebase does not use relative paths, but everything works fine for them, so I must be missing something in my project: https://github.com/Microsoft/vscode/blob/0e81224179fbb8f6fda18ca7362d8500a263cfef/src/vs/languages/typescript/common/typescript.ts#L7-L14

You can check out my GitHub repo, but in case it helps here's the tsconfig.json file I'm using:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "noImplicitAny": false,
    "removeComments": false,
    "preserveConstEnums": true,
    "sourceMap": true,
    "outDir": "dist"
  },
  "exclude": [
    "dist",
    "node_modules"
  ]
}

Funny thing is, building the project through webpack using ts-loader works fine, so I'm guessing it's just a configuration issue...

@vladima replied to this issue on GitHub:

The way how compiler resolves modules is controlled by moduleResolution option that can be either node or classic (more details and differences can be found here). If this setting is omitted the compiler treats this setting to be node if module is commonjs and classic - otherwise. In your case if you want classic module resolution strategy to be used with commonjs modules - you need to set it explicitly by using

{
    "compilerOptions": {
        "moduleResolution": "node"
    }
}

tsc throws `TS2307: cannot find module` for local file, @vladima answered this issue on GitHub : The way the compiler modules are managed is controlled by moduleResolution, which can be either node or classic​  Could not find a declaration file for module 'module-name'. '/path/to/module-name.js' implicitly has an 'any' type 0 configure the jest moduleNameMapper not work

In VS2019, the project property page, TypeScript Build tab has a setting (dropdown) for "Module System". When I changed that from "ES2015" to CommonJS, then VS2019 IDE stopped complaining that it could find neither axios nor redux-thunk (TS2307).

tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": "src",
    "forceConsistentCasingInFileNames": true,
    "jsx": "react",
    "lib": [
      "es6",
      "dom",
      "es2015.promise"
    ],
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "outDir": "build/dist",
    "rootDir": "src",
    "sourceMap": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "es5",
    "skipLibCheck": true,
    "strict": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true
  },
  "exclude": [
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts",
    "node_modules",
    "obj",
    "**/*.spec.ts"
  ],
  "include": [
    "src",
    "src/**/*.ts",
    "@types/**/*.d.ts",
    "node_modules/axios",
    "node_modules/redux-thunk"
  ]
}

[project-references] TS2307 with direct file imports (imports that , packages/pkg2/src/index.ts:2:20 - error TS2307: Cannot find module (instead of tsbuild) c:\temp\learn-a>node c:\TypeScript\built\local\tsc.js -p  I have read similiar questions including tsc throws `TS2307: Cannot find module` for a local file . I have a privat external module (on a local git server) and I try to include that into my application - this works.

The vscode codebase does not use relative paths, but everything works fine for them

Really depends on your module loader. If you are using systemjs with baseurl then it would work. VSCode uses its own custom module loader (based on an old version of requirejs).

Recommendation

Use relative paths as that is what commonjs supports. If you move files around you will get a typescript compile time error (a good thing) so you will be better off than a great majority of pure js projects out there (on npm).

Cannot import modules with "absolute" path when `module` set to , Actual behavior: I get TS2307 errors: app/index.ts(1,21): error TS2307: Cannot find module 'components/counter  TS2307: Unable to find 'angular2 / core' module when importing Angular2 to TypeScript Hi I have a lil bit of Angular 1 background, I am learning Angular 2. for starting up with Angular 1, only dependency is to add the angular sources either the angular.js or angular.min.js, when trying the same with the Angular 2 via script tag, <s

If use webstorm, press Ctrl+Alt+S and bring up the settings window. Languages&Frameworks>TypeScript, enable "use tsconfig.json" option.

TS2307: Cannot find module error but the application compiles and , Thanks a lot! Putting the following vue-shim.d.ts declaration file under my ./src directory solves the problem:. jedmao changed the title tsc can't find a module, even though Visual Studio Code has no problems. tsc can't find a module, even though Visual Studio Code has no problems with it. Aug 3, 2015 jedmao changed the title tsc can't find a module, even though Visual Studio Code has no problems with it. tsc 1.5.3 can't find a module, even though Visual

I was in trouble to import an Enum in typescript

error TS2307: Cannot find module...

What I did to make it work was migrate the enum to another file and make this change:

export enum MyEnum{
    VALUE = "MY_VALUE"
}

to

export enum MyEnum{
    VALUE = 1
}

Typescript: “Cannot find module” with valid typings - node.js - html, Typescript: “Cannot find module” with valid typings - node.js. I have also tried compiling using gulp-typescript, gulp-tsc, and tsc directly on the command line. I use local imports quite happily: where src/utils/immerReducer is a local file import { GetNamedReducer } from '/utils/immerReducer'; throws an error 2) Push all  @mhegazy That sounds great. I look forward to it. 2 Questions. First, does the package author need to do the same for their bower package? Second, I still have to use an absolute path for my internal project modules.

Tsconfig paths cannot find module, baseUrl — should already be there): I have read similiar questions including tsc throws `TS2307: Cannot find module` for a local file . ”) to be specified and  In typescript(*.tsx) files I cannot import svg file with this statement: import logo from './logo.svg'; Transpiler says:[ts] cannot find module './logo.svg'. My svg file is just <svg></svg>. But in .js file I'm able to import it without any issues with exact the same import statement. I suppose it has something to do with type of svg file

ts-node, TypeScript execution environment and REPL for node.js, with source map support. Tip: Installing modules locally allows you to control and share the versions TS Node will always resolve the compiler from cwd before checking TypeScript Node does not use files , include or exclude , by default. The file has a .ts extension. I'm new to JavaScript and to TypeScript, but I was under the impression that fs was a core module, so how could it not be found? How do I fix the problem? Other things that I tried already: Putting a simple function body in the file and then compiling on the command line with tsc.

tsc+throws+TS2307+Cannot+find+module+for+a+local+file, Typescript must be "transpiled" into JavaScript using the tsc compiler, which A TypeScript configuration file called tsconfig.json guides the compiler as it When the compiler doesn't recognize something, it throws an error. You don't need to do anything to get typings files for library packages that include d.ts files. Using Angular 6, I am having trouble with my material-moment-adapter. In my moment-date-adapter.d.ts file it shows that "'module' cannot be found" on my import statements when trying to import { M

Comments
  • I am seeing this error: error TS5023: Unknown compiler option 'moduleResolution'.
  • Can't find this configuration. Where is it?
  • It is located in tsconfig.json file.
  • Loading the vscode codebase in Visual Studio Code itself, I get no squiggly lines, so Visual Studio Code somehow understands things like import {notImplemented} from 'vs/base/common/errors';, regardless of where the file that contains that code lives. How do they do it?
  • In WebStorm 2020.1 this option has been reworded to say, "Also for projects without tsconfig.json."