web-infra-dev / web-infra-dev/rslib
[Bug]: Can't resolve self-referencing
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1k
- Forks
- 67
- Avg merge
- 6h 9m
- Merged PRs (30d)
- 57
Description
Version
/
Details
Given a package named @monorepo/self for example. If trying to bare import package itself. webpack / Rspack can't resolve the package. It works in webpack / Rspack with exports field when exports target could be resolved. But when not, for example the source is TS, it will failed to resolve.
// index.js
import { a } from './a.js'
import { b } from './b.js'
export { a, b }
// a.js
export const a = 1
// b.js
import { a } from '@monorepo/self'
export const b = 1 + a
error message:
> @monorepo/self@ build:webpack /Users/bytedance/Projects/webpack-test-out-library-esm-output/packages/self-import
> webpack --config rspack.config.mjs
asset main.mjs 2.07 KiB [compared for emit] [javascript module] (name: main)
runtime modules 670 bytes 3 modules
orphan modules 78 bytes [orphan] 2 modules
./src/index.mjs + 2 modules 141 bytes [built] [code generated]
ERROR in ./src/b.js 1:0-34
Module not found: Error: Can't resolve '@monorepo/self' in '/Users/bytedance/Projects/webpack-test-out-library-esm-output/packages/self-import/src'
@ ./src/index.mjs 2:0-22 4:0-15
ERROR in ./src/index.mjs 4:0-15
export 'default' (reexported as 'a') was not found in './a.js' (possible exports: a)
ERROR in ./src/index.mjs 4:0-15
export 'default' (reexported as 'b') was not found in './b.js' (possible exports: b)
1 error has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
webpack 5.93.0 compiled with 3 errors in 48 ms
ELIFECYCLE Command failed with exit code 1.
Reproduce link
/
Reproduce Steps
/
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with the files shown in index.js, a.js, and b.js and the webpack command using rspack.config.mjs. Trace how the self-reference import is resolved when the package exports target cannot be resolved. Done means the package can resolve its own import in this source scenario without the reported module-not-found error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100