Skip to content

Commit

Permalink
fix: failed to resolve promise when eager import a dynamic cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed May 7, 2024
2 parents c586c7b + 5091d37 commit ea9094b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ContextModule.js
Expand Up @@ -845,7 +845,7 @@ module.exports = webpackAsyncContext;`;
const thenFunction =
fakeMap !== 9
? `${arrow ? "id =>" : "function(id)"} {
${this.getReturnModuleObjectSource(fakeMap)}
${this.getReturnModuleObjectSource(fakeMap, true)}
}`
: RuntimeGlobals.require;
return `var map = ${JSON.stringify(map, null, "\t")};
Expand Down
1 change: 1 addition & 0 deletions test/cases/mjs/namespace-object-lazy/cjs-dynamic.js
@@ -0,0 +1 @@
module.exports = Promise.resolve(1);
10 changes: 10 additions & 0 deletions test/cases/mjs/namespace-object-lazy/index.mjs
Expand Up @@ -26,6 +26,16 @@ it("should receive a namespace object when importing commonjs with __esModule",
.catch(done);
});

it("should resolve the promise returned by the imported dynamic commonjs", function (done) {
const post = "dynamic.js";
import(/* webpackMode: "eager" */ "./cjs-" + post) // context module
.then(function (result) {
expect(result).toBe(1);
done();
})
.catch(done);
});

function contextCJS(name) {
return Promise.all([
import(`./dir-cjs/${name}.js`),
Expand Down
@@ -0,0 +1 @@
module.exports = Promise.resolve(1);
10 changes: 10 additions & 0 deletions test/cases/mjs/non-mjs-namespace-object-lazy/index.js
Expand Up @@ -12,6 +12,16 @@ it("should receive a namespace object when importing commonjs with __esModule",
}).catch(done);
});

it("should resolve the promise returned by the imported dynamic commonjs", function (done) {
const post = "dynamic.js";
import(/* webpackMode: "eager" */ "./cjs-" + post) // context module
.then(function (result) {
expect(result).toBe(1);
done();
})
.catch(done);
});

function contextCJS(name) {
return Promise.all([
import(`./dir-cjs/${name}`),
Expand Down

0 comments on commit ea9094b

Please sign in to comment.