Unverified Commit 6ea64002 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

fix(next-swc): Enable `ignoreDynamic` for auto_cjs (#45836)

This PR enables `ignoreDynamic` for common js modules which is detected
by `auto_cjs` pass.


Fixes https://github.com/vercel/next.js/issues/40231.


---

I verified that with this change the test reproduction does not fail
with import error.

---------
parent a8b3e780
......@@ -33,13 +33,13 @@ DEALINGS IN THE SOFTWARE.
use auto_cjs::contains_cjs;
use either::Either;
use fxhash::FxHashSet;
use serde::Deserialize;
use std::cell::RefCell;
use std::rc::Rc;
use std::{path::PathBuf, sync::Arc};
use next_binding::swc::core::{
base::config::ModuleConfig,
common::{chain, comments::Comments, pass::Optional, FileName, SourceFile, SourceMap},
ecma::ast::EsVersion,
ecma::parser::parse_file_as_module,
......@@ -287,7 +287,9 @@ impl TransformOptions {
};
if should_enable_commonjs {
self.swc.config.module = Some(ModuleConfig::CommonJs(Default::default()));
self.swc.config.module = Some(
serde_json::from_str(r##"{ "type": "commonjs", "ignoreDynamic": true }"##).unwrap(),
);
}
self
......
function loadSomethingWithDynamicImport(param) {
return import(`something/${param}`).then(r => r.default)
}
module.exports = { loadSomethingWithDynamicImport }
\ No newline at end of file
"use strict";
function loadSomethingWithDynamicImport(param) {
return import("something/".concat(param)).then(function(r) {
return r.default;
});
}
module.exports = {
loadSomethingWithDynamicImport: loadSomethingWithDynamicImport
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment