A module whose compilation fails is removed from the cache, but another
module compiled earlier in the same cycle may still import it. Executing
such an import returned an error without setting an exception, so the
shell reported an unrelated TypeError.
Throw "Cannot load module" instead, and add a shell test for a cyclic
dependency of a module that fails to compile.
m = njs_module_find(vm, &module->name, 0);
if (njs_slow_path(m == NULL)) {
+ if (!njs_is_valid(&vm->exception)) {
+ njs_error(vm, "Cannot load module \"%V\"", &module->name);
+ }
+
return NJS_ERROR;
}
--- /dev/null
+import dep from './cyclic_compile_exception_dep.js';
+export default dep;
+@
--- /dev/null
+import parent from './cyclic_compile_exception.js';
+export default 'dep';
"'name'\r\n>> "}
} "-n njs"
+njs_test {
+ {"import broken from './test/js/module/cyclic_compile_exception.js';\r\n"
+ "SyntaxError:*\r\n*>> "}
+ {"import dep from './test/js/module/cyclic_compile_exception_dep.js';\r\n"
+ "Error: Cannot load module*cyclic_compile_exception.js*\r\n*>> "}
+ {"1 + 1\r\n"
+ "2\r\n>> "}
+} "-n njs"
+
# CLI OPTIONS
# help