TypeScript does not resolve typings for aliased module

Viewed 33

I have a TypeScript application with a custom WebPack config where I'm going to resolve some module (application config) at the compilation step. So I added an alias to webpack config:

  resolve: {
    alias: {
      config:
        process.env.NODE_ENV === "production"
          ? path.resolve(__dirname, "../configs/config.prod")
          : path.resolve(__dirname, "../configs/config"),
    },
    ...

also added custom typings for this module:

import { Config } from "../configs/config.types";

declare module "config" {
  const _config: Config;
  export default _config;
}

The problem is that my typings don't work and I see an error "Cannot find module 'config' or its corresponding type declarations." in the file where "config" module is imported.

I think my tsconfig (below) is correct because other typings work as expected. I was only able to solve this with '@ts-ignore' however can not understand the problem and looking for a solution to rid of '@ts-ignore' comments in my code.

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "isolatedModules": true,
    "jsx": "react-native",
    "lib": ["es2015", "dom"],
    "types": ["reflect-metadata", "@types/jest"],
    "moduleResolution": "node",
    "module": "commonjs",
    "resolveJsonModule": true,
    "noEmit": true,
    "strict": true,
    "target": "ES2015",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "sourceMap": true,
    "typeRoots": ["types"],
    "useDefineForClassFields": true
  },
  "include": ["src", "types", "webpack", "configs"]
}
0 Answers
Related