{"record":{"id":"c44cbf09ac30b886","repo":"remix-run/remix","slug":"transform-failed","errorCode":"TRANSFORM_FAILED","errorMessage":"Failed to analyze HMR usage in transformed script. ${parseResult.errors[0]?.message ?? 'Unknown parse error'}","messagePattern":"Failed to analyze HMR usage in transformed script\\. (.+?)","errorType":"error_code","errorClass":"AssetServerCompilationError","httpStatus":null,"severity":"error","filePath":"packages/assets/src/lib/scripts/transform.ts","lineNumber":324,"sourceCode":"\nexport function getHmrAnalysis(rawCode: string): TransformedModule['hmr'] {\n  let mayUseImportMetaHot = rawCode.includes('import.meta.hot')\n  let usesImportMetaHot = false\n  let acceptedDeps: HmrAcceptedDependency[] = []\n  let selfAccepting = false\n\n  if (mayUseImportMetaHot) {\n    try {\n      let parseResult = parseSync('hmr-analysis.js', rawCode, {\n        lang: 'js',\n        sourceType: 'module',\n      })\n\n      if (parseResult.errors.length > 0) {\n        throw createAssetServerCompilationError(\n          `Failed to analyze HMR usage in transformed script. ${parseResult.errors[0]?.message ?? 'Unknown parse error'}`,\n          {\n            code: 'TRANSFORM_FAILED',\n          },\n        )\n      }\n\n      walkAst(parseResult.program, (node) => {\n        if (isImportMetaHotNode(node)) {\n          usesImportMetaHot = true\n        }\n\n        if (node.type !== 'CallExpression') return\n        if (!isImportMetaHotAcceptCallee(node.callee)) return\n\n        let [firstArgument] = node.arguments\n        if (firstArgument === undefined || !isAcceptedDependencyArgument(firstArgument)) {\n          selfAccepting = true\n          return\n        }\n","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/assets/src/lib/scripts/transform.ts#L306-L342","documentation":"After transforming a script, the pipeline re-parses the output to detect `import.meta.hot` usage for HMR analysis. If the parser reports errors on the transformed output, the HMR analysis cannot proceed and TRANSFORM_FAILED is thrown with the first parser message. This indicates the transform itself produced invalid JavaScript, not that the original source was invalid.","triggerScenarios":"getHmrAnalysis running parse on transformed code that no longer parses — typically caused by a transform/loader emitting syntax the configured parser rejects, or a broken source-map-preserving rewrite (e.g. from a custom module loader or minifier step).","commonSituations":"Custom module loaders (runModuleLoaders chain) that return code with unbalanced braces or target syntax beyond the parser's configured ECMA version; incompatible plugin/loader versions after an upgrade; injected HMR preamble snippets that corrupt the output.","solutions":["Inspect the full transformed output for the failing module (log the code passed to parse) and fix the loader/transform that emits invalid syntax","Update or remove custom module loaders implicated in the chain; check loader version compatibility","If using a minifier/other transform, run it after HMR analysis or configure it to emit parseable ES output","Report/check upstream if the unmodified pipeline fails on valid ESM input"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (e) {\n  if (isAssetServerCompilationError(e) && e.code === 'TRANSFORM_FAILED') {\n    logger.error(`HMR parse failed: ${e.message}`, e.cause)\n    // disable the implicated loader or fall back to serving untransformed ESM\n  } else throw e\n}","preventionTips":["Keep loader/transform plugin versions in lockstep with the assets package","Test custom loaders against a fixture that includes import.meta.hot usage","Parse loader output in the loader's own tests before shipping it"],"tags":["hmr","transform","parser","assets"],"backgroundTag":"transform-output-parse-failed","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}