Pharus Migrates from CommonJS to ESM to Support Lighthouse v10; Resolves ts-node Issues with Loaders API
Key point
Pharus introduces its migration from CommonJS to ESM to adopt Lighthouse v10, resolving ts-node path-alias and CommonJS file compilation issues using the Node.js Loaders API.
Details
Google's Lighthouse v10 switched to an ESM-based architecture, causing functional limitations and requiring significant code changes for Pharus, which operated in a CommonJS environment, when using dynamic imports or CJS entry points. Consequently, Pharus decided to fully migrate to ESM. Two major issues arose during the migration process. First, path aliases in tsconfig were not resolved when running with ts-node. This was resolved by using Node.js's --loader flag to create a resolve hook integrated with the tsconfig-paths library, converting aliases to absolute paths. Second, syntax errors occurred when importing the share package, written in CommonJS within the monorepo, from the runner package that had been migrated to ESM. This was addressed by forcing those files to be parsed as ESM format via a load hook, and separating configuration files that used __dirname into .mts extension files using import.meta.url.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.