title: Import statements in Nodejs with Typescript is not resolving with absolute path after compiling
body: <p>I am trying to write a server in NodeJs using Typescript. I have installed these <code>devDependencies</code>:</p>
  <pre><code>    &quot;@types/config&quot;: &quot;^0.0.38&quot;,
      &quot;@types/express&quot;: &quot;^4.17.12&quot;,
      &quot;@types/jsonwebtoken&quot;: &quot;^8.5.1&quot;,
      &quot;@types/lodash&quot;: &quot;^4.14.170&quot;,
      &quot;@types/morgan&quot;: &quot;^1.9.2&quot;,   
  
      &quot;nodemon&quot;: &quot;^2.0.7&quot;,
      &quot;tslint&quot;: &quot;^6.1.3&quot;,
      &quot;typescript&quot;: &quot;^4.3.2&quot;
  </code></pre>
  <p>My <code>tsconfig.json</code> is something like this:</p>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      /* Visit https://aka.ms/tsconfig.json to read more about this file */
  
      /* Basic Options */
      // &quot;incremental&quot;: true,                         /* Enable incremental compilation */
      &quot;target&quot;: &quot;es5&quot;,                                /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
      &quot;module&quot;: &quot;commonjs&quot;,                           /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
      // &quot;lib&quot;: [],                                   /* Specify library files to be included in the compilation. */
      // &quot;allowJs&quot;: true,                             /* Allow javascript files to be compiled. */
      // &quot;checkJs&quot;: true,                             /* Report errors in .js files. */
      // &quot;jsx&quot;: &quot;preserve&quot;,                           /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
      // &quot;declaration&quot;: true,                         /* Generates corresponding '.d.ts' file. */
      // &quot;declarationMap&quot;: true,                      /* Generates a sourcemap for each corresponding '.d.ts' file. */
      &quot;sourceMap&quot;: true,                           /* Generates corresponding '.map' file. */
      // &quot;outFile&quot;: &quot;./&quot;,                             /* Concatenate and emit output to single file. */
      &quot;outDir&quot;: &quot;./dist/&quot;,                              /* Redirect output structure to the directory. */
      &quot;rootDir&quot;: &quot;./src&quot;,                          /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
      // &quot;composite&quot;: true,                           /* Enable project compilation */
      // &quot;tsBuildInfoFile&quot;: &quot;./&quot;,                     /* Specify file to store incremental compilation information */
      // &quot;removeComments&quot;: true,                      /* Do not emit comments to output. */
      // &quot;noEmit&quot;: true,                              /* Do not emit outputs. */
      // &quot;importHelpers&quot;: true,                       /* Import emit helpers from 'tslib'. */
      // &quot;downlevelIteration&quot;: true,                  /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
      // &quot;isolatedModules&quot;: true,                     /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
  
      /* Strict Type-Checking Options */
      // &quot;strict&quot;: true,                                 /* Enable all strict type-checking options. */
      // &quot;noImplicitAny&quot;: true,                       /* Raise error on expressions and declarations with an implied 'any' type. */
      // &quot;strictNullChecks&quot;: true,                    /* Enable strict null checks. */
      // &quot;strictFunctionTypes&quot;: true,                 /* Enable strict checking of function types. */
      // &quot;strictBindCallApply&quot;: true,                 /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
      // &quot;strictPropertyInitialization&quot;: true,        /* Enable strict checking of property initialization in classes. */
      // &quot;noImplicitThis&quot;: true,                      /* Raise error on 'this' expressions with an implied 'any' type. */
      // &quot;alwaysStrict&quot;: true,                        /* Parse in strict mode and emit &quot;use strict&quot; for each source file. */
  
      /* Additional Checks */
      // &quot;noUnusedLocals&quot;: true,                      /* Report errors on unused locals. */
      // &quot;noUnusedParameters&quot;: true,                  /* Report errors on unused parameters. */
      // &quot;noImplicitReturns&quot;: true,                   /* Report error when not all code paths in function return a value. */
      // &quot;noFallthroughCasesInSwitch&quot;: true,          /* Report errors for fallthrough cases in switch statement. */
      // &quot;noUncheckedIndexedAccess&quot;: true,            /* Include 'undefined' in index signature results */
      // &quot;noImplicitOverride&quot;: true,                  /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
      // &quot;noPropertyAccessFromIndexSignature&quot;: true,  /* Require undeclared properties from index signatures to use element accesses. */
  
      /* Module Resolution Options */
      &quot;moduleResolution&quot;: &quot;node&quot;,                  /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
      &quot;baseUrl&quot;: &quot;./src&quot;,                             /* Base directory to resolve non-absolute module names. */
      // &quot;paths&quot;: {},                                 /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
      // &quot;rootDirs&quot;: [],                              /* List of root folders whose combined content represents the structure of the project at runtime. */
      // &quot;typeRoots&quot;: [],                             /* List of folders to include type definitions from. */
      // &quot;types&quot;: [],                                 /* Type declaration files to be included in compilation. */
      // &quot;allowSyntheticDefaultImports&quot;: true,        /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
      &quot;esModuleInterop&quot;: true,                        /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
      // &quot;preserveSymlinks&quot;: true,                    /* Do not resolve the real path of symlinks. */
      // &quot;allowUmdGlobalAccess&quot;: true,                /* Allow accessing UMD globals from modules. */
  
      /* Source Map Options */
      // &quot;sourceRoot&quot;: &quot;&quot;,                            /* Specify the location where debugger should locate TypeScript files instead of source locations. */
      // &quot;mapRoot&quot;: &quot;&quot;,                               /* Specify the location where debugger should locate map files instead of generated locations. */
      // &quot;inlineSourceMap&quot;: true,                     /* Emit a single file with source maps instead of having a separate file. */
      // &quot;inlineSources&quot;: true,                       /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
  
      /* Experimental Options */
      // &quot;experimentalDecorators&quot;: true,              /* Enables experimental support for ES7 decorators. */
      // &quot;emitDecoratorMetadata&quot;: true,               /* Enables experimental support for emitting type metadata for decorators. */
  
      /* Advanced Options */
      &quot;skipLibCheck&quot;: true,                           /* Skip type checking of declaration files. */
      &quot;forceConsistentCasingInFileNames&quot;: true        /* Disallow inconsistently-cased references to the same file. */
    },
    &quot;include&quot;: [ &quot;src/**/*&quot;],
    &quot;exclude&quot;: [ &quot;node_modules&quot; ]
  }
  
  </code></pre>
  <p>My project directory structure is somethig like this:</p>
  <pre><code>src
   -&gt; app
      -&gt; bootstrap
      -&gt; api
      -&gt; models
      -&gt; ..... more directories
      -&gt; server.ts
  
  dist
   -&gt;app //generated files in .js
      -&gt; boostrap
      -&gt; api
      -&gt; ..... more directories
      -&gt; server.js    
  </code></pre>
  <p>My <code>server.ts</code> file has following absolute working imports:</p>
  <pre><code>import express from 'express';
  
  import bootstrap from 'app/bootstrap'
  
  import logger from 'app/services/logger';
  
  const port = process.env.PORT || 8200;
  
  const app = express();
  
  bootstrap(app).then(mongo=&gt;{
    app.listen({ port }, () =&gt; logger.info(`Server is listening on ${port}`));
  }).catch(error=&gt;{
    logger.error(error);
    process.exit(1);
  });
  
  </code></pre>
  <p>The problem is when these <code>.ts</code> files are compiled and <code>.js</code> files are generated. and I run the application inside <code>dist/app/server.js</code>, I get cannot find module error, which node js throws due to my absolute path imports. Please help me fix this.</p>
  <p>This is generated <code>server.js</code> file:</p>
  <pre><code>&quot;use strict&quot;;
  var __importDefault = (this &amp;&amp; this.__importDefault) || function (mod) {
      return (mod &amp;&amp; mod.__esModule) ? mod : { &quot;default&quot;: mod };
  };
  Object.defineProperty(exports, &quot;__esModule&quot;, { value: true });
  var express_1 = __importDefault(require(&quot;express&quot;));
  var bootstrap_1 = __importDefault(require(&quot;app/bootstrap&quot;));
  var logger_1 = __importDefault(require(&quot;app/services/logger&quot;));
  var port = process.env.PORT || 8200;
  var app = express_1.default();
  bootstrap_1.default(app).then(function (mongo) {
      app.listen({ port: port }, function () { return logger_1.default.info(&quot;Server is listening on &quot; + port); });
  }).catch(function (error) {
      logger_1.default.error(error);
      process.exit(1);
  });
  //# sourceMappingURL=server.js.map
  </code></pre>
  <p>Here
  <code>require(&quot;app/bootstrap&quot;)</code> and <code>require(&quot;app/services/logger&quot;)</code> are producing error.</p>