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

When rolldown handles external modules,it should replace the source in the ImportDeclaration with oxc-resolver to return the result in the error #1185

Closed
zhusjfaker opened this issue May 21, 2024 · 2 comments · Fixed by #1254
Labels
bug Something isn't working

Comments

@zhusjfaker
Copy link
Collaborator

zhusjfaker commented May 21, 2024

in esbuild repo

https://github.com/evanw/esbuild/blob/main/internal/bundler_tests/bundler_packagejson_test.go#L2878

in rolldown esbuild test package_json case

https://github.com/rolldown/rolldown/tree/main/crates/rolldown/tests/esbuild/packagejson/.test_package_json_subpath_import_node_builtin_issue3485

oxc-resolver test unit case

   #[test]
    fn test_resolver_package_json_bad_main() {
        let options = ResolveOptions {
            alias_fields: vec![vec!["browser".into()]],
            exports_fields: vec![vec!["exports".into()]],
            condition_names: vec!["node".into(), "import".into(), "require".into()],
            main_fields: vec!["main".into()],
            // alias: vec![("#fs".into(),vec!["fs".into()] ), ("#http".into(),vec![ "node:http".into()])],
            ..ResolveOptions::default()
        };
        let dir = Path::new("/Users/jason.zhu/Desktop/github/rolldown/crates/rolldown/tests/esbuild/packagejson/test_package_json_subpath_import_node_builtin_issue3485");
        let resolver = Resolver::new(options);
        let res = resolver.resolve(dir, "#http").unwrap();
        println!("res-> \n {:#?}", res);
    }

terminal output

failures:

---- tests::test_resolver_package_json_bad_main stdout ----
thread 'tests::test_resolver_package_json_bad_main' panicked at tests/mod.rs:90:50:
called `Result::unwrap()` on an `Err` value: NotFound("node:http")
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1649:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1073:23
   4: mod::tests::test_resolver_package_json_bad_main
             at ./tests/mod.rs:90:19
   5: mod::tests::test_resolver_package_json_bad_main::{{closure}}
             at ./tests/mod.rs:79:45
   6: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

In the result,it can clearly see that oxc-resolver has converted #http to node:http based on the imports field.

I personally suggest that you need to compare whether the source in ast is consistent with the returned result, and if not, you need to replace it with the result of the resolver.

rolldown current result

entry.mjs

// do not replace the imports fileds
import { default as fs } from "#fs";
import { default as http } from "#http";

// entry.js
fs.readFileSync();
http.createServer();
@hyf0
Copy link
Member

hyf0 commented May 21, 2024

I have something in mind to fix this. It requires to change the core code a little bit and I'm thinking how to apply the fix.

@hyf0
Copy link
Member

hyf0 commented May 24, 2024

Need to wait for oxc-project/oxc-resolver#164.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants