All jobs

Fix "line" is not a registered controller When Upgrading Chart.js

Yes. An agent upgrades Chart.js from 2 to 4 in its sandbox, registers the controller, elements and scales the chart needs, ports the v2 options and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and reads how the chart is built. In a Vite and TypeScript app like augustinbegue/gpx-visualizer, package.json has chart.js at ^2.9.4 with @types/chart.js at ^2.9.35, vite at ^2.8.0 and typescript at ^4.5.4, and the build script is tsc && vite build. The lock file (lockfileVersion 2) resolves chart.js to 2.9.4. src/chartjs/generateCharts.ts does import { Chart } from "chart.js" and calls new Chart(speedChartCtx, { type: 'line', data: speedChartData, options: chartOptions }). chartOptions.ts is written for v2: a tooltips block with enabled: false, custom: customTooltip, mode: 'index' and intersect: false, and scales as arrays, yAxes with three linear axes named elevation-axis, speed-axis and index-axis (the last with display: false) and xAxes with one axis named distance, each with a ticks.callback and gridLines: { drawOnChartArea: false }. getChartData.ts returns three datasets (Elevation, Speed, Location) that pick an axis with yAxisID, typed as Chart.ChartData from the global namespace the v2 types declare, and customTooltip.ts loads the library a second time with const { default: Chart } = await import('chart.js'). The one workflow, .github/workflows/node.js.yml, runs npm install --dev and npm run build on Node 16.

It builds first with the pinned version to have a baseline: 44 modules transform and dist/assets/index.727e4303.js is 194.90 KiB. Then it installs chart.js@4 (4.6.1 today) and removes @types/chart.js, since v3 and later ship their own types. tsc now reports 24 errors: TS2322 on the scales arrays at chartOptions.ts lines 22 and 54, because scales are keyed by id in v4, TS7006 implicit any on every tick callback, and TS2503 "Cannot find namespace 'Chart'" in customTooltip.ts, getChartData.ts and src/leaflet/animation/animate.ts. vite build on its own still succeeds, because Vite does not type-check, which is exactly why this breakage reaches the browser.

The runtime error is the one the title names. The agent reproduces it in Node with a stub canvas rather than guessing: with nothing registered, new Chart throws Error: "line" is not a registered controller. After registering LineController, LineElement and PointElement the next throw is Error: "category" is not a registered scale., because the x axis in the v2 options has no type and defaults to category. Registering CategoryScale and LinearScale as well lets the chart construct with scales x and y, and so does the one-line alternative, import Chart from "chart.js/auto", which registers everything. The default import from the bare package is gone: import Chart from "chart.js" is a SyntaxError ("does not provide an export named 'default'"), so the dynamic import in customTooltip.ts yields nothing and gets rewritten to the named export.

The agent picks explicit registration, since the app renders one line chart and has no reason to ship every controller. It rewrites chartOptions.ts into the v4 shape (scales keyed by elevation-axis, speed-axis, index-axis and distance, grid in place of gridLines, the tooltip under plugins.tooltip with external in place of custom), replaces the Chart.ChartData, Chart.ChartTooltipModel and Chart.ChartPoint namespace types with imports from chart.js, types the tick callbacks, and runs tsc and vite build until both are clean. Each option rename is listed in the pull request against the line it came from.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Upgrade chart.js from 2.x to the current 4.x in this repository and fix everything that breaks. Read package.json, the lock file, and every file under src that imports chart.js or uses the Chart namespace types first, and run the existing build to have a baseline. After upgrading, remove @types/chart.js, run tsc and fix every error it reports; then reproduce the runtime error (\"line\" is not a registered controller, then \"category\" is not a registered scale) and fix it by registering exactly the controller, elements and scales this app uses, not by importing chart.js/auto, unless the app renders more than one chart type. Port the v2 options (tooltips, scales arrays, gridLines) to their v4 names and keep each axis id. Rewrite any dynamic default import of chart.js to the named export. Run tsc and the build until both pass, and open a pull request that lists every option rename against the line it came from and quotes the runtime errors you reproduced.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that bumps chart.js in package.json and the lock file, drops @types/chart.js, adds a Chart.register(...) call next to the one new Chart in generateCharts.ts, rewrites chartOptions.ts into the keyed v4 shape, and changes the type imports in getChartData.ts, customTooltip.ts and animate.ts. The description quotes the two runtime errors in the order they appear and the 24 tsc errors the upgrade produced, and pastes the clean tsc and vite build output after the fix.

A reviewer checks three things: that every axis id survived the rename, since the datasets select axes by yAxisID; that the tooltip still calls the custom handler, now through plugins.tooltip.external; and that the registration list matches the chart type in use. The build output in the description shows the bundle still has one entry chunk and one vendor chunk, so nothing was accidentally split or doubled by a second copy of the library.

Run it on every Monday morning

An automation in the Project that holds the repository, with a schedule trigger, a cron of 0 7 * * 1 and the team's timezone, runs this prompt each Monday. Chart.js is one line of a weekly upgrade run; the prompt can name it alone, as here, or ask for every dependency with a major release and a build or test run after each. A run an automation starts has its own max_runs_per_hour cap and is not tied to an API key.

From your own scheduler instead, send this body to POST /o/{org}/sessions with a request_id that is a UUID v5 of the week's date, so a retried cron job returns the run it already started rather than opening a second pull request. The key's webhook_url receives run.completed or run.failed with the session URL when the run ends.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

A Chart.js major upgrade fails in the browser, not in the terminal: vite build is green while new Chart throws on the first page load. The agent's sandbox is where that gap closes. It installs the new version, runs tsc to surface the 24 type errors, and reproduces the registration errors in Node before touching a line, and every one of those commands and its output stays in the run's record, so the pull request quotes the actual error text rather than a paraphrase from a migration guide.

It is also work nobody wants to schedule on a laptop. The upgrade sits in the queue until someone has an afternoon, and by then two more majors have shipped. On Rush the run starts on a schedule or from one API call, works in its own sandbox with the repository checked out, and ends in a pull request with the build output attached, so the review is a diff and a log instead of a half-day of context rebuilding.

Frequently asked questions

Why not just import chart.js/auto and be done?

It works, and the prompt allows it when the app renders several chart types. chart.js/auto registers every controller, scale, element and plugin, which is the v2 behaviour. For an app with one line chart, explicit registration keeps the bundle to what the chart uses, and the agent lists exactly which classes it registered so a later chart type is one more entry in the same call.

Will it change the look of the chart?

The agent ports options name for name: gridLines becomes grid, the array of axes becomes an object keyed by the same ids, tooltips.custom becomes plugins.tooltip.external. Defaults did change between v2 and v4, so the pull request names any option the agent had to set explicitly to keep the old rendering, and the reviewer looks at the chart once before merging.

The build passes today. How did the error get into production?

Vite transpiles TypeScript without checking it, so an upgrade that breaks the types still produces a bundle. In this repository the build script runs tsc first, which is what catches the 24 errors; the registration error is a runtime check inside Chart.js and only appears when a chart is constructed, which is why the agent reproduces it in Node before and after the fix.

Does it work with Chart.js 3?

The registration model and the option names are the same from 3.0 on, so the same changes apply. The agent upgrades to the current major unless the prompt names one, and quotes the installed version in the pull request.

More jobs like this: Upgrade dependencies weekly

Keep reading