{"record":{"id":"877d012a7cf93736","repo":"santifer/career-ops","slug":"cannot-import-generate-pdf-mjs-e-code-e-message-skipping","errorCode":null,"errorMessage":"Cannot import generate-pdf.mjs (${e.code || e.message}) — skipping behavioral section-order tests","messagePattern":"Cannot import generate-pdf\\.mjs \\((.+?)\\) — skipping behavioral section-order tests","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"test-all.mjs","lineNumber":2730,"sourceCode":"// Same gap, same two shipped Chinese markets (#3658): modes/zh-TW and modes/zh\n// rendered titles the alias table could not name, so the guard was disabled AND\n// cv.sections — the documented way to correct an order — silently did nothing.\n// Both scripts are required: a CV written in either renders through this table.\nfor (const header of ['專業摘要', '工作經歷', '學歷', '證照', '技能', '专业摘要', '工作经历', '学历', '证书', '项目']) {\n  if (generatePdfScript.includes(`['${header}',`)) {\n    pass(`SECTION_ALIASES maps Chinese header: ${header}`);\n  } else {\n    fail(`SECTION_ALIASES missing Chinese header: ${header}`);\n  }\n}\n\n// generate-pdf.mjs imports playwright at module scope; degrade to a warning\n// rather than crashing the suite where it is not installed.\nlet pdfModule = null;\ntry {\n  pdfModule = await import(pathToFileURL(join(ROOT, 'generate-pdf.mjs')).href);\n} catch (e) {\n  warn(`Cannot import generate-pdf.mjs (${e.code || e.message}) — skipping behavioral section-order tests`);\n}\n\nif (pdfModule) {\n  const { sectionKey, validateCvSectionOrder } = pdfModule;\n\n  // Canonical keys are language-independent; only the spelling differs.\n  const keyCases = [\n    ['Podsumowanie zawodowe', 'summary'],\n    ['Kompetencje kluczowe', 'competencies'],\n    ['Kluczowe kompetencje', 'competencies'], // word-order variant\n    ['Doświadczenie zawodowe', 'experience'],\n    ['Przebieg kariery', 'experience'],\n    ['Wykształcenie', 'education'],\n    ['Certyfikaty', 'certifications'],\n    ['Umiejętności', 'skills'],\n    ['Wyksztalcenie', 'education'],  // diacritics stripped\n    ['Umiejetnosci', 'skills'],      // diacritics stripped\n    ['Work Experience', 'experience'], // English must be unchanged","sourceCodeStart":2712,"sourceCodeEnd":2748,"githubUrl":"https://github.com/santifer/career-ops/blob/e7abd431fce9348a95261acac9e0c14779c35df8/test-all.mjs#L2712-L2748","documentation":"generate-pdf.mjs imports Playwright at module scope, so dynamic import of it fails in environments without Playwright installed. test-all.mjs catches that import error and warns that the behavioral section-order tests are skipped rather than letting the suite crash.","triggerScenarios":"`await import(pathToFileURL(join(ROOT, 'generate-pdf.mjs')).href)` rejects — typically with ERR_MODULE_NOT_FOUND because the playwright package is missing, or a syntax/compat error (non-zero e.code, message in e.message) in generate-pdf.mjs itself.","commonSituations":"Fresh clones without `npm install`, CI jobs that skip browser dependencies, Node version mismatch making the module fail to parse, or a broken generate-pdf.mjs after an edit.","solutions":["Run `npm install` (or `npm i playwright && npx playwright install chromium`) in the repo root so the module imports.","Read e.code/e.message in the warning: ERR_MODULE_NOT_FOUND → install deps; syntax errors → fix generate-pdf.mjs.","If you only need the pure functions (sectionKey, validateCvSectionOrder), consider importing from a module that does not pull Playwright at top level.","Accept the skip if CV rendering is irrelevant to your change — it is an intentional degradation."],"exampleFix":"// before (generate-pdf.mjs)\nimport { chromium } from 'playwright';\n// after (lazy, so importers without playwright still work)\nlet chromium;\nexport async function getChromium() { ({ chromium } = await import('playwright')); return chromium; }","handlingStrategy":"try-catch","validationCode":"let importable = true; try { await import(pathToFileURL('generate-pdf.mjs').href); } catch { importable = false; } if (!importable) console.warn('run npm install to enable pdf tests');","typeGuard":"const pdfImportable = (m) => m !== null && typeof m.validateCvSectionOrder === 'function';","tryCatchPattern":"try { pdfModule = await import(pathToFileURL(join(ROOT, 'generate-pdf.mjs')).href); } catch (e) { warn(`Cannot import generate-pdf.mjs (${e.code || e.message})`); }","preventionTips":["Always `npm install` after cloning and after package.json changes","Keep Playwright imports out of modules that export pure logic","Check e.code to distinguish missing deps from syntax errors","Skip browser-dependent tests intentionally in slim CI jobs"],"tags":["playwright","module-import","optional-dependency","test-runner"],"backgroundTag":"missing-optional-dependency","analyzedSha":"e7abd431fce9348a95261acac9e0c14779c35df8","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}