Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Breaking change on v1.4.2: replacement for non-alias 🤯 #103

Closed
pp0rtal opened this issue Mar 14, 2022 · 6 comments
Closed

Breaking change on v1.4.2: replacement for non-alias 🤯 #103

pp0rtal opened this issue Mar 14, 2022 · 6 comments

Comments

@pp0rtal
Copy link

pp0rtal commented Mar 14, 2022

Hi!
I've got a second bug spotted on (first minor here), and since 1.4.2
and I think this one is quite interesting as it's replacing a NodeJs native library import statement.

Description / steps to reproduce

  1. tsconfig.json alias config doesn't matter!
"path": {} // empty
  1. file to convert /utils/index.js, which does contain a Node.js native package
    (for instance cluster, but it works for a child_process, fs or whatever)
const cluster = require("cluster");
  1. And, I've got some file /cluster.js:
// the bug occurs as long the file "cluster" exists

The /utils/index.js will be rewritten as following 🤯 🤯 🤯

const cluster = require("../cluster");

Origin

That's not the same source as the minor bug I've spot!
This issue is coming from this commit: 18b252a

// Finding breaking change in tagged versions
1.4.1: OK! :)
1.4.2: BROKEN!

// Finding breaking in commits
e980fee75851012c52878c0d23c2dc05fe83bce4: (1.4.1): OK
18b252a5de960b813490ce6fa6e3a447b943d61e: BROKEN

... note it's broken to current version 1.6.4

I'm trying to spot exactly which code did this regression, probably replaceBaseUrlImport but I'm not sure to be able to edit this code without breaking things 😞

Let me know if I can help

@raouldeheer
Copy link
Contributor

Try this config: #79 (comment)

@pp0rtal
Copy link
Author

pp0rtal commented Mar 14, 2022

@raouldeheer Thanks for your quick answer!

I tried to add tsc-alias config in my tsconfig.json as following

{
    "compilerOptions": {
        "baseUrl": ".",  // If I understand this is the problem source, and yes my project files are in root fs :/
         ...
    },
    ....
    "ts-node": {}, // I've got some ts-node config working for instance
    "tsc-alias": {
        "replacers": {
            "BaseUrl": {
                "enabled": false
            }
        }
    }

But I still have the same issue

@raouldeheer
Copy link
Contributor

raouldeheer commented Mar 14, 2022

The name of BaseUrl has been changed to base-url all lowercase.

@justkey007
Copy link
Owner

@pp0rtal please replace BaseUrl with base-url.

@pp0rtal
Copy link
Author

pp0rtal commented Mar 14, 2022

@raouldeheer cc @justkey007 Works perfectly know! 😄
And I see you fixed the original solution perfect 👍
I'm closing ticket then.


Just by curiosity
I'm surprised this behavior is the default, what is the use-case of this?
Shouldn't be base-url default to false, and activated for edge cases?

@raouldeheer
Copy link
Contributor

raouldeheer commented Mar 14, 2022

"All module imports with non-relative names are assumed to be relative to the baseUrl." -typescript handbook
This is why base-url is enabled by default.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants