-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Resolve wrong path when import sub-path module with browser field #2002
Copy link
Copy link
Closed
Description
Background:
esbuild/internal/resolver/package_json.go
Lines 185 to 191 in 105361d
| // Browserify allows a browser map entry of "./pkg" to override a package | |
| // path of "require('pkg')". This is weird, and arguably a bug. But we | |
| // replicate this bug for compatibility. However, Browserify only allows | |
| // this within the same package. It does not allow such an entry in a | |
| // parent package to override this in a child package. So this behavior | |
| // is disallowed if there is a "node_modules" folder in between the child | |
| // package and the parent package. |
Bad Test Cases:
esbuild/internal/bundler/bundler_default_test.go
Lines 1392 to 1411 in e5e149d
| func TestSubImportModuleWithPkgBrowser(t *testing.T) { | |
| default_suite.expectBundled(t, bundled{ | |
| files: map[string]string{ | |
| "/entry.js": ` | |
| import { v } from "pkg/sub"; | |
| console.log(v); | |
| `, | |
| "/node_modules/pkg/package.json": `{ "browser": { "./sub": "./sub/index.js" } }`, | |
| "/node_modules/pkg/sub/index.js": ` | |
| export { version as v } from "sub"; | |
| `, | |
| "/node_modules/sub/index.js": `export const version = 123`, | |
| }, | |
| entryPaths: []string{"/entry.js"}, | |
| options: config.Options{ | |
| Mode: config.ModeBundle, | |
| AbsOutputFile: "/out.js", | |
| }, | |
| }) | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels