You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is a module not found in rolldown an external module?
How to define an external module
from case
path: /crates/rolldown/tests/esbuild/packagejson/test_package_json_exports_alternatives
test_package_json_exports_alternatives
expect esbuild output in terminal
✘ [ERROR] Could not resolve "pkg/apples/red.js"
src/test_package_json_exports_alternatives/src/entry.js:1:21:
1 │ import redApple from 'pkg/apples/red.js'
╵ ~~~~~~~~~~~~~~~~~~~
The module "./good-apples/red.js" was not found on the file system:
src/test_package_json_exports_alternatives/node_modules/pkg/package.json:3:18:
3 │ "./apples/": ["./good-apples/", "./bad-apples/"],
╵ ~~~~~~~~~~~~~~~~
You can mark the path "pkg/apples/red.js" as external to exclude it from the bundle, which will
remove this error and leave the unresolved path in the bundle.
✘ [ERROR] Could not resolve "pkg/books/red"
src/test_package_json_exports_alternatives/src/entry.js:3:20:
3 │ import redBook from 'pkg/books/red'
╵ ~~~~~~~~~~~~~~~
The module "./good-books/red-book.js" was not found on the file system:
src/test_package_json_exports_alternatives/node_modules/pkg/package.json:4:18:
4 │ "./books/*": ["./good-books/*-book.js", "./bad-books/*-book.js"]
╵ ~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "pkg/books/red" as external to exclude it from the bundle, which will remove
this error and leave the unresolved path in the bundle.
but now rolldown will bundle process result is successful
dist/entry.js
// These modules are treated as external. not throw any error or panic import{defaultasredApple}from"pkg/apples/red.js";import{defaultasredBook}from"pkg/books/red";// node_modules/pkg/good-apples/green.jsvargreen_default='\u{1f34f}';// node_modules/pkg/good-books/green-book.jsvargreen_book_default='\u{1f4d7}';// src/entry.jsconsole.log({
redApple,greenApple:green_default,
redBook,greenBook:green_book_default});
// line 72let resolved = resolver.resolve(importer.map(Path::new), request, import_kind)?;Ok(resolved.map(|resolved| ResolvedRequestInfo{path: resolved.path,module_type: resolved.module_type,is_external:false,package_json: resolved.package_json,}))// Instead of dealing with oxc-resolver errors, we opt for direct passthroughs, // whereas oxc returns a not-found error if it can't resolve.
// line 288/* Here you can clearly see that all the not-found errors from the previous passthrough are treated as external modules. */match resolved_id {Ok(info) => {
ret.push(info);}Err(e) => match&e {ResolveError::NotFound(..) => {
warnings.push(BuildError::unresolved_import_treated_as_external(
specifier.to_string(),self.resolved_path.path.to_string(),Some(e),).with_severity_warning(),);
ret.push(ResolvedRequestInfo{path: specifier.to_string().into(),module_type:ModuleType::Unknown,is_external:true,package_json:None,});}
_ => {
build_errors.push((&dependencies[idx], e));}},}}
The text was updated successfully, but these errors were encountered:
Personally, I think external is a local module that needs to be tagged or http, if it's written as a local module and not tagged, it should throw an error.
We used to throw errors for implicit external modules. And for better DX, I changed to throw warnings rather than errors, which will terminate the build.
We could add a option to control wether throw errors for implicit external modules. Let's wait for feedbacks.
hyf0
changed the title
[Need for discussion] Is a module not found in rolldown an external module? How to define an external module
Rolldown should throw errors for implicit external modules
May 20, 2024
We used to throw errors for implicit external modules. And for better DX, I changed to throw warnings rather than errors, which will terminate the build.
We could add a option to control wether throw errors for implicit external modules. Let's wait for feedbacks.
If there's a final conclusion, maybe I can help implement the code.
Is a module not found in rolldown an external module?
How to define an external module
from case
path: /crates/rolldown/tests/esbuild/packagejson/test_package_json_exports_alternatives
test_package_json_exports_alternatives
expect esbuild output in terminal
but now rolldown will bundle process result is successful
dist/entry.js
Cause analysis
crates/rolldown_plugin/src/utils/resolve_id_with_plugins.rs
crates/rolldown/src/module_loader/normal_module_task.rs
The text was updated successfully, but these errors were encountered: