I want to setup my project so where ever I use the line below:
import { BlahBlahService } from '@blahblah/core/BlahBlahService';
it is resolved to:
./dist/blahblah/core/BlahBlahService
I already have read through online resources and applied the instructed settings (which I also include below). This is working in Visual Studio Code; i.e. It is not showing error to me hence it is able to correctly read my settings at tsconfig and understand it. I want to make the same thing happen to Webpack.
However I am getting the following error:
ERROR in ./xxxxxxxxxxx.ts Module not found: Error: Can't resolve '@blahblah/core/BlahBlahService' in 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
I have the following setup in my web application:
I also have the following in my tsconfig:
"compilerOptions": {
    ...
    "baseUrl": ".",
    "paths": {
       "@blahblah/core": ["./dist/blahblah/core"],
       "@blahblah/core/*": ["./dist/blahblah/core/*"],
    }
    ...
 }
And I have the following setting in my webpack.js file:
plugins: [
    ...
    new TsConfigPathsPlugin(),
    ...
],
                ts-loader uses tsc , the TypeScript compiler, and relies on your tsconfig. json configuration. Make sure to avoid setting module to "CommonJS", or webpack won't be able to tree-shake your code.
It performs type checking in a separate process with ts-loader just handling transpilation.
Like Babel, Webpack depends on TSC to transpile TypeScript to JavaScript but as TSC doesn't have a clue about Webpack, hence Webpack needs a loader to talk to TSC. This is where the ts-loader comes into play. Webpack compiles a TypeScript file using ts-loader package which asks TSC to do the compilation.
I'm currently working with [email protected] and [email protected].
Same issue. I found the solution in a github issue.  
tsconfig.js:
"compilerOptions": {
    ...
    "baseUrl": ".",
    "paths": {
        "~/*": ["./src"],
    }
}
webpack.config.js:
var TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;
resolve: {
    alias: {
        "~/": "./src"
    },
    plugins: [
        new TsConfigPathsPlugin()
    ]
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With