oxc-project / oxc-resolver

Rust version of webpack/enhanced-resolve
https://oxc.rs/docs/guide/usage/resolver.html
MIT License
122 stars 18 forks source link

Err: PackagePathNotExported #257

Closed ilteoood closed 1 week ago

ilteoood commented 2 weeks ago

Hi, I'm facing an issue while using oxc-resolver, version 1.12.0, to resolve all the dependencies of the node-red.

To reproduce it, please follow these steps:

I expect it to be resolved correctly, like NodeJS does, but instead the following error is returned:

failed to resolve: Err(PackagePathNotExported(".", ...)

The content of the message is:

Package subpath '.' is not defined by "exports" in ...

Am I missing something in the configuration in order to make it behave like node?

ilteoood commented 2 weeks ago

I see the same behaviour even when I try to analyze glob in another project. Could it be related to the format of the export field? AFAIK is valid, don't know why oxc doesn't recognize it.

Boshen commented 1 week ago

let path = PathBuf::from_str(format!("{}/packages/node_modules/@node-red/util/lib/i18n.js"), node_red_clone_path).unwrap();

This needs to be a directory, not a file.

ilteoood commented 1 week ago

@Boshen I've changed by test to match the following:

#[test]
    fn test_resolve_cjs() {
        let node_red_clone_path = "/path/to/cloned/node-red";
        let resolver = Resolver::new(ResolveOptions::default());

        let result = resolver.resolve(PathBuf::from_str(node_red_clone_path).unwrap(), "i18next");

        assert!(result.is_ok(), "failed to resolve: {:?}", result);
    }

But the error is still the same:

failed to resolve: Err(PackagePathNotExported(".", "/Users/ilteoood/Documents/git/personal/node-red/node_modules/i18next/package.json"))

But the files are actually there: image

ilteoood commented 1 week ago

To make it work, I have to change the resolver configuration as follows:

let resolver = Resolver::new(ResolveOptions {
            exports_fields: vec![],
            imports_fields: vec![],
            ..Default::default()
        });
Boshen commented 1 week ago

The error message is burried in the README 😅

https://github.com/oxc-project/oxc-resolver/blob/main/README.md#errors--trouble-shooting