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

[Bug]: source build fails to transform path alias of dependency's dependency #2687

Closed
yf-yang opened this issue Jun 24, 2024 · 4 comments
Closed

Comments

@yf-yang
Copy link

yf-yang commented Jun 24, 2024

Version

System:
    OS: macOS 13.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 520.72 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Browsers:
    Chrome: 126.0.6478.63
    Safari: 16.3
  npmPackages:
    @modern-js/app-tools: ^2.54.2 => 2.54.2 
    @modern-js/runtime: ^2.54.2 => 2.54.2 
    @modern-js/tsconfig: ^2.54.2 => 2.54.2

Details

Say there is a monorepo

  • apps/app is the application
  • app depends on dep
  • dep depends on dep2

Now with source build enabled, app can transform path aliases of dep. However, it cannot transform path aliases of dep2.

For example,
the same line import { Person } from '@/decorator'; could be transformed when it is in dep, but cannot be transformed when it is in dep2

Reproduce link

https://github.com/yf-yang/modernjs-monorepo-example/tree/resolve-dep-bug

Reproduce Steps

pnpm i
cd apps/app
pnpm dev

An error would be thrown, telling that @/decorator fails to be resolved.
By commenting out the foo2 call in dep/src/foo.ts, the error goes away. Note that dep/src/foo.ts also imports from @/decorator.

Can you confirm if this is a modern.js bug or a rspack bug?

@yf-yang
Copy link
Author

yf-yang commented Jun 24, 2024

🤨However, by explicitly adding dep2 to app's project reference, it could be transformed. However I still think this is a corner case that should be taken care by the dev server

@chenjiahan chenjiahan transferred this issue from web-infra-dev/modern.js Jun 24, 2024
@chenjiahan
Copy link
Member

Transfered to Rsbuild repo

@yf-yang
Copy link
Author

yf-yang commented Jun 24, 2024

My configuration of exports field is not correct.

  "exports": {
    ".": {
      "source": "./src/index.ts",
      "types": [
        "./dist/index.d.ts",
        "./src/index.ts"
      ],
      "import": "./dist/index.js",
      "require": "./dist/index.cjs",
      "default": "./dist/index.js"
    }
  }

is the correct way.

For more information, check @rsbuild/plugin-source-build code.

hasExportsSourceField(p.metaData.exports || {}, fieldName))

@yf-yang yf-yang closed this as completed Jun 24, 2024
@chenjiahan
Copy link
Member

Get, conditional exports without subpath will be supported in next version

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

No branches or pull requests

2 participants