/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/configCases/runtime/module-not-found-error/index.js
39 строк
1 KB
hai-x
fix: throw module not found error after interception (#20510)
23 фев 2026, 20:53
Не верифицирован
23 фев 2026, 20:53
13c1694
Код
Авторство
О чём код?
it("should throw helpful error when module is not found at runtime", function () { // First, require the helper module to get its id const helper = require("./helper"); expect(helper).toBe("helper"); // Find the module id for helper.js const moduleId = Object.keys(__webpack_modules__).find((id) => id.includes("helper") ); expect(moduleId).toBeDefined(); // Delete the module from cache and modules to simulate a corrupted state delete __webpack_module_cache__[moduleId]; delete __webpack_modules__[moduleId]; // Now trying to require the module should throw a helpful error matching Node.js format let thrownError; try { require("./helper"); } catch (e) { thrownError = e; } expect(thrownError).toBeDefined(); expect(thrownError.message).toMatch(/Cannot find module/); expect(thrownError.code).toBe("MODULE_NOT_FOUND"); // Ensure the module cache is cleared let thrownError2; try { require("./helper"); } catch (e) { thrownError2 = e; } expect(thrownError2).toBeDefined(); expect(thrownError2.message).toMatch(/Cannot find module/); expect(thrownError2.code).toBe("MODULE_NOT_FOUND"); });