module: throw error when re-runing errored module jobs · nodejs/node@515b581
@@ -323,7 +323,7 @@ class ModuleJob extends ModuleJobBase {
323323assert(this.module instanceof ModuleWrap);
324324let status = this.module.getStatus();
325325326-debug('ModuleJob.runSync', this.module);
326+debug('ModuleJob.runSync()', status, this.module);
327327// FIXME(joyeecheung): this cannot fully handle < kInstantiated. Make the linking
328328// fully synchronous instead.
329329if (status === kUninstantiated) {
@@ -358,6 +358,7 @@ class ModuleJob extends ModuleJobBase {
358358}
359359360360async run(isEntryPoint = false) {
361+debug('ModuleJob.run()', this.module);
361362assert(this.phase === kEvaluationPhase);
362363await this.#instantiate();
363364if (isEntryPoint) {
@@ -461,7 +462,11 @@ class ModuleJobSync extends ModuleJobBase {
461462assert(this.phase === kEvaluationPhase);
462463// This path is hit by a require'd module that is imported again.
463464const status = this.module.getStatus();
464-if (status > kInstantiated) {
465+debug('ModuleJobSync.run()', status, this.module);
466+// If the module was previously required and errored, reject from import() again.
467+if (status === kErrored) {
468+throw this.module.getError();
469+} else if (status > kInstantiated) {
465470if (this.evaluationPromise) {
466471await this.evaluationPromise;
467472}
@@ -482,6 +487,7 @@ class ModuleJobSync extends ModuleJobBase {
482487}
483488484489runSync(parent) {
490+debug('ModuleJobSync.runSync()', this.module);
485491assert(this.phase === kEvaluationPhase);
486492// TODO(joyeecheung): add the error decoration logic from the async instantiate.
487493this.module.async = this.module.instantiateSync();