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

Resolve wrong path when import sub-path module with browser field #2002

Closed
ycjcl868 opened this issue Feb 8, 2022 · 0 comments
Closed

Resolve wrong path when import sub-path module with browser field #2002

ycjcl868 opened this issue Feb 8, 2022 · 0 comments

Comments

@ycjcl868
Copy link
Contributor

ycjcl868 commented Feb 8, 2022

Background:

// 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:

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",
},
})
}

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

Successfully merging a pull request may close this issue.

1 participant