'Original JavaScript source path is invalid

Using Webpack to build my Typescript files and output to a bundle.js. The problem is that in the bundle.js the path to the original Typescript files is incorrect.

Example of an invalid path:

/***/ "./services/events/session.ts":
/*!************************************!*\
!*** ./services/events/session.ts ***!

When the file hits the debugger its saying the file is located in the following path:

C:\PProjects\PISource\services\events\session.ts

but it should be in

C:\PProjects\PISource\source_crm\services\events\session.ts

My project structure is

C:\PProjects\PISource\source_crm\services\events\session.ts C:\PProjects\PISource\source_crm\build\services\bundle.js

My webpack config file is:

'use strict';

const path = require('path');
const nodeExternals = require('webpack-node-externals');

module.exports = {
    mode: 'development',
    target: 'node',
    devtool: 'eval-source-map',
    entry: './services/main.ts',
    output: {
        filename: 'bundle.js',
        path: path.join(__dirname, 'build/services')
    },
    watch: true,
    module: {
        rules: [
            {
                test: /\.ts?$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
                options: {
                    configFile: 'tsconfig-services.json',
                },
            },
            {
                test: /\.html$/,
                use: [
                    {
                        loader: 'html-loader',
                        options: { minimize : false }
                    }
                ]
            }           
        ],
    },

    externals: [nodeExternals()],
    resolve: {
        extensions: ['*', '.ts', '.tsx', '.js', '.scss', '.css'],
        fallback: {
        },
    },
};

And the typescript config file:

{
    "compilerOptions": {
        "module": "commonjs",
        "removeComments": true,
        "lib": ["es2015", "es2017", "dom"],
        "noUnusedLocals": false, 
        "noUnusedParameters": false, 
        "sourceMap": false,
        "inlineSourceMap": true,
        "inlineSources": true,
        "allowJs": true,
        "target": "es2017",
        //"outDir": "./build/services",
        //"rootDir": "services",
        "noImplicitAny": false,
        "types": ["node"],
        "typeRoots": ["node_modules/@types"],
        "paths": {
            "crypto": ["./node_modules/crypto-js"]
        }
    },
    "include": ["services/**/*.ts"],
    "exclude": ["node_modules", "**/*.spec.ts"]
}

I tried "outDir" and "rootDir" but didn't work so I commented it out to see if it made a difference.

Any thought on what is missing to correct the path?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source