question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tsconfig-paths safe for production?

See original GitHub issue

Hi, is tsconfig-path safe to use in production?

And what about perfomance impact of runtime module resolution?

Do you have any insight on these topics?

Thank you for solving this annoying absolute path resolution problem!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

21reactions
sriramr98commented, Feb 1, 2020

Any insights on how to use tsconfig-paths with tsc when building the project? tsconfig-paths works well with node and ts-node but not with tsc

2reactions
cadesalaberrycommented, Jul 23, 2022

For the record, I ran into the same issue and ended up using the tsc-alias package to replace the alias names with their relative path in the outDir folder.

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "lib": [
            "ES6"
        ],
        "experimentalDecorators": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "target": "es6",
        "noImplicitAny": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "declaration": true,
        "composite": true,
        "rootDir": "./src",
        "outDir": "./dist",
        "baseUrl": "./src", // Make sure we can replace it by "dist" in the production code (with TS_NODE_BASEURL)
        "paths": {
            "@helpers/*": ["helpers/*"],
            "@middlewares/*": ["middlewares/*"],
            "@topics/*": ["topics/*"],
            "@app": ["app"]
        }
    },

    "ts-node": {
        "require": ["tsconfig-paths/register"]
    },

    "exclude": [
        "node_modules",
        "**/dist/*"
    ],

    "include": [
        "src/**/*",
    ],
}

package.json

{
  ...
  "main": "dist/index.js",
  "engines": {
    "node": "16"
  },
  "scripts": {
    "yarn": "yarn install --frozen-lockfile",
    "yarn:production": "yarn install --frozen-lockfile --production",
    "start:compiled": "TS_NODE_BASEURL=./dist node dist/index.js",
    "start:dev": "ts-node src",
    "build": "rm -rf ./dist && rm -f tsconfig.tsbuildinfo && npx tsc && tsc-alias -p tsconfig.json",
    "test": "jest"
  },
  "devDependencies": {
    ...
    "tsconfig-paths": "^3.9.0",
    "ts-jest": "^28.0.5",
    "ts-node": "^10.8.2",
    "typescript": "^4.7.4"
  },
  "dependencies": {
    ...
    "tsc-alias": "^1.7.0"
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
All relative paths found in the configuration file will be resolved ... While you can use TypeScript to produce JavaScript code from TypeScript...
Read more >
tsconfig-paths - npm Package Health Analysis - Snyk
The npm package tsconfig-paths was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as...
Read more >
Why are these tsconfig paths not working? - Stack Overflow
I did a bit of digging and found that the tryPaths array produced by tsconfig-paths has absolute URLs relative to the project /cwd...
Read more >
How to handle tsconfig path aliases : r/typescript - Reddit
Since VScode just loads the tsconfig files, it will all be fine and dandy in the IDE but then when running tests or...
Read more >
Why TypeScript Paths Failed Me | Mitchell Simoens Blog
Oh good man why?! Yes, there is a fourth issue. When you are running code in development, TypeScript only loads a single tsconfig.json...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found