justkey007 / tsc-alias

Replace alias paths with relative paths after typescript compilation
MIT License
876 stars 63 forks source link

Using `resolveFullPaths` with watch mode cause the transpiled file not to have `.js` extenstion #117

Closed nmsobri closed 2 years ago

nmsobri commented 2 years ago

As title, When using resolveFullPaths in watch mode, the transpiled file doesnt have .js extension It work just fine without watch mode

tsconfig.json

{
    "compilerOptions": {
             ....
    },
    "tsc-alias": {
        "verbose": false,
        "resolveFullPaths": true,
    }
}

And run tsc -w & tsc-alias -w causing the transpiled file lost its extension

raouldeheer commented 2 years ago

@slier81 can you provide us the console output when running with -r debugger.js? Working version and nonworking version? debugger.js file placed next to tsconfig.json. With the debugger.js file contents being:

const util = require('util');
let loggedConfig = true;
exports.default = ({ orig, file, config }) => {
    if (loggedConfig) {
        console.log(util.inspect(config, {showHidden: false, depth: null, colors: true}));
        loggedConfig = false;
    }
    console.log(orig);
    console.log(file);
    return orig;
};
nmsobri commented 2 years ago

@raouldeheer Running tsc && tsc-alias -r debugger.js give me: ( i need to exclude -w flag cause i need to see the error )

tsc-alias error: Failed to import replacer "debugger.js"

Here is my project structure:

.
├── debugger.js
├── package-lock.json
├── package.json
├── src
│   ├── app.ts
│   ├── controller
│   │   └── home.ts
│   ├── middleware
│   ├── model
│   │   └── home.ts
│   ├── route
│   │   └── v1
│   │       └── route.ts
│   ├── server.ts
│   └── service
│       └── home.ts
└── tsconfig.json
tkcto commented 2 years ago

@raouldeheer so whats the update on this?

raouldeheer commented 2 years ago

@tkcto I haven't been able to reproduce this bug. That makes it exceedingly difficult to give a time estimate.

nmsobri commented 2 years ago

@raouldeheer ah ic.. to add some context, when using w flag, tsc-alias no longer translate path alias ( and does not add .js extension )

btw, i developed in vscode remote devcontainer, is there something related to it?

nmsobri commented 2 years ago

@raouldeheer i have setup demo repo for you with reproducible bug https://github.com/slier81/tscalias-bug-demo

raouldeheer commented 2 years ago

@slier81 I've tried running the dev:compile script, but it doesn't seem to start tsc-alias. Changed the dev:compile script from:

tsc -w & tsc-alias -w

To:

concurrently \"tsc -w\" \"tsc-alias -w\"

After doing that it worked and replaced aliases.

Can you try this? This could fix the issue.

Replacing the dev:compile script to this would also solve the issue.

"dev:tsc": "tsc -w",
"dev:tsc-alias": "tsc-alias -w",
nmsobri commented 2 years ago

@raouldeheer

@slier81 I've tried running the dev:compile script, but it doesn't seem to start tsc-alias. Changed the dev:compile script from:

tsc -w & tsc-alias -w

To:

concurrently \"tsc -w\" \"tsc-alias -w\"

After doing that it worked and replaced aliases.

Can you try this? This could fix the issue.

Replacing the dev:compile script to this would also solve the issue.

"dev:tsc": "tsc -w",
"dev:tsc-alias": "tsc-alias -w",

Yes this fix the issue.. But the second solution apparently only work, if there is already generated output. But according to your documentation "build:watch": "tsc -w & tsc-alias -w" should work.. Why running tsc -w & tsc-alias -w dont work? Maybe you need to update your documentation? thx anyway for the fix.. Greatly appreciated

nmsobri commented 2 years ago

I have to mention this, actually solution number 1 concurrently \"tsc -w\" \"tsc-alias -w\" , actually also not working if this is the first time you running this command ( meaning, there is no generated output yet ).. On subsequent running of this command, it will work.. Quick fix would be tsc && (concurrently \"tsc -w\" \"tsc-alias -w\")

oleksandr-danylchenko commented 2 years ago

@nmsobri Thank you! I faced the same exact problem and the tsc && (concurrently \"tsc -w\" \"tsc-alias -w\") helped!

@raouldeheer, could you please put it in the docs? Because it's pretty confusing on the first interaction with the library to not be able to work with it in the watch mode :sweat_smile: