Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 97371

Typescript path aliases not resolved correctly at runtime

$
0
0

I'm running VS Code and I am currently trying to set up some aliases on my typescript project.

My dev setup rest on nodemon and ts-node, the code gets compiled to a dist folder.

So far, I succeeded to get Typescript Hero to manage the import with aliases:

alias resolution vscode

So far, my folder structure is:

.
└─┬ src
  ├──modules
  ├────Category
  ├────Ressource
  ├──shared
  ├────debug

// tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "moduleResolution": "node",
        "pretty": true,
        "sourceMap": true,
        "target": "es6",
        "outDir": "./dist",
        "baseUrl": "./src",
        "paths": {
            "@shared/*": [
                "shared/*"
            ],
            "@modules/*": [
                "modules/*"
            ]
        },
        "resolveJsonModule": true,
        "esModuleInterop": true
    },
    "include": [
        "src/**/*.ts"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts",
        "**/*.test.ts",
    ]
}

And this is the first alias import that fails.

//Server.ts file
import Print from '@shared/debug/Print.class';
import App from './App';

const MyApp: App = new App();

MyApp.ExpressApp.listen(MyApp.Config.ExpressPort, () => {
    Print.Log('Express server listening on port ' + MyApp.Config.ExpressPort);
});

However, I get an error: "Cannot find module '@shared/debug/Print.class'" on "cross-env NODE_ENV=development nodemon ts-node ./src/server.ts". CMD logs

And this is where I stand.

Now, I've read some Q&A on SO, and it seems that even if I managed to make the aliases works while in dev, it would fail in production, as I'm running from Typescript src folder and my deliverable are built in dist ? If so, is there any way to remediate ? Many thanks


Viewing all articles
Browse latest Browse all 97371

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>