Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Regression in v0.19 when using relative imports and paths from tsconfig #3354

Closed
andyvanee opened this issue Aug 28, 2023 · 10 comments
Closed
Labels

Comments

@andyvanee
Copy link

I believe this may be related to other issues, but haven't seen a minimal reproduction expressed elsewhere:

Expected output - v0.18.20 processes relative import correctly

Regression - v0.19 resolves the relative import incorrectly

The most relevant pieces to this reproduction are:

  1. Including a wildcard in compilerOptions.paths
  2. Using a relative import which could be resolved by a path-relative import
{
  "compilerOptions": {
    "paths": {
      "*": ["web/*"]
    }
}
// web/bar/foo/index.ts
// This relative import is problematic in v0.19 since it resolves to `web/foo` rather than `web/bar/foo`
export {foo} from './foo'

The output in v0.19 translates the example into a recursive function since web/bar/foo/index.ts is masked by web/foo.ts

// web/foo.ts
function foo() {
  console.log("web/foo");
  foo();                                  // <- this is the wrong function reference
}

// entry.ts
foo();
@andyvanee
Copy link
Author

andyvanee commented Aug 28, 2023

I have resolved this issue by adding an explicit path aliases for relative imports, but this seems like a pretty strange workaround:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      ".": ["."],
      "./*": ["./*"],
      "*": ["web/*"]
    }
  }
}

@taylorthurlow
Copy link

Same issue, and @andyvanee's workaround also worked for me - thanks for posting this.

@briancavalier
Copy link

Seeing a similar issue. Doesn't seem to be exactly the same context, but may have the same root cause. For us, it's manifesting as our build missing an export from package in the same monorepo as an application. Reverting to 0.18.20 works for us. We haven't tried @andyvanee's workaround of adding explicit relative import paths yet. Will report back if we try that.

@ilijapuaca
Copy link

We seem to have a similar issues, import paths (non-relative) which are set up as aliases through paths no longer get resolved properly since 0.19.0. We are not marking any of these packages as external, and the workaround above did not seem to work

@steabert
Copy link

We seem to have a similar issues, import paths (non-relative) which are set up as aliases through paths no longer get resolved properly since 0.19.0. We are not marking any of these packages as external, and the workaround above did not seem to work

There was an update with a fix for the resolution behaviour in v0.19.1, you can retry the work-around with that version.

@ilijapuaca
Copy link

There was an update with a fix for the resolution behaviour in v0.19.1, you can retry the work-around with that version.

I tried both 0.19.1 and 0.19.2, having the same issue

@briancavalier
Copy link

I tried both 0.19.1 and 0.19.2, having the same issue

Same here. 0.19.0-0.19.2 reproduce our issue. We haven't tried 0.19.3 yet.

@andyvanee
Copy link
Author

There was an update with a fix for the resolution behaviour in v0.19.1, you can retry the work-around with that version.

Without seeing a reproduction case, I'm not sure if @ilijapuaca is having the same issue, but you can see from my original reproduction that none of the 0.19.x versions address the issue: Regression - v0.19 resolves the relative import incorrectly

The expected output should be two function definitions as it is in 0.18.x:

// web/bar/foo/foo.ts
function foo() {
  console.log("bar/foo");
}

// web/foo.ts
function foo2() {
  console.log("web/foo");
  foo();
}

// entry.ts
foo2();

While the actual output from 0.19.x is an infinitely recursive function:

// web/foo.ts
function foo() {
  console.log("web/foo");
  foo();
}

// entry.ts
foo();

@steabert
Copy link

There was an update with a fix for the resolution behaviour in v0.19.1, you can retry the work-around with that version.

I tried both 0.19.1 and 0.19.2, having the same issue

Note that I was only referring to the work-around needing 0.19.1 (for me at least). The issue still remains.

@lnist
Copy link

lnist commented Oct 11, 2023

Possibly related, we had to change import * as typechain from "./typechain"; to import * as typechain from "./typechain/index"; otherwise esbuild picks up the node_modules/typechain path instead of the local "./typechain".

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

No branches or pull requests

7 participants