1

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.

  • phpStorm can resolve the classes perfectly!
  • the app throws the error TS2307 but runs perfectly!

I wonder why the transpiler throws this error although everything looks fine and I need this error to be gone for a stable deployment.

The module tsconfig.json looks like:

{
    "compilerOptions": {
        "module": "commonjs",
        "moduleResolution": "node",
        "target": "ES6",
        "typeRoots": [
            "node_modules/@types"
        ],
        "sourceMap": false,
        "noImplicitAny": false,
        "declaration": true,
        "noResolve": false
    },
    "version": "2.0.0"
}

I tried several combinations of the above without success.

I have a Main.ts in the module like

export {default as Logger}  from "./Logger";
export {ILogger as ILogger} from './ILogger';

Where the class and the interface are

export interface ILogger { }
export default class Logger implements ILogger { }

And in the app I use:

import {Logger, ILogger} from "logging";

The error happens when I try to transpile the app, not the module. Again, everything works when running the app through node and when coding in phpStorm but on transpiling I get:

src/Main.ts(9,39): error TS2307: Cannot find module 'logging'.

Update:

Looks like a bug in tsc: https://github.com/Microsoft/TypeScript/issues/14332

Community
  • 1
  • 1
Daniel W.
  • 31,164
  • 13
  • 93
  • 151

2 Answers2

0

In our project error was resolved by including typescript files and definitions in include key as follows

  "include": ["global.d.ts", "./app/**/*.tsx", "./app/**/*.ts"],

app contains typescript files and global.d.ts contains declarations for local packages as follows

declare module 'uicomponents-react-native';
declare module '@styles';
declare module '@styles/*';

declare module '@common';

declare module '@constants';
declare module '@constants/*';

declare module '@utils/*';
declare module '@utils';

declare module '@helper/*';
declare module '@helper';
Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73
-1

We just had to set

"noResolve": false

to true and it finally did work.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151