We've released new versions of Flarum's JavaScript build tooling: flarum-webpack-config 3.1.0, flarum/jest-config 2.1.1 and Flarum CLI 3.0.15. They fix the most common ways extension builds were breaking, and bring extensions onto the same toolchain Flarum's bundled extensions now use.
Do you need to rebuild? If your extension doesn't lazy-load anything with import(), it's existing build keeps working with Flarum 2.0 and with the upcoming 2.1. If it does, rebuild with flarum-webpack-config 3.1.0: until then, your lazily loaded chunks can collide with another extension's, and fail with errors like r[e] is not a function or the wrong code loading.
What's fixed in 3.1.0
check-typings breaking after a lockfile refresh. flarum-webpack-config used to supply TypeScript 4.9, which can't read current versions of @types/node. Any yarn upgrade or fresh install could then break check-typings, with errors coming from node_modules rather than your own code (#5120). 3.1.0 supplies TypeScript 5.9.
- "could not find a copy of webpack to link". Yarn 1 often failed to upgrade flarum-webpack-config because webpack was both a dependency and a peer. In 3.1.0, webpack is only a peer dependency, so the upgrade goes through.
- flarum/jest-config 2.1.1 tests against the same Mithril version Flarum ships (2.2.8), and requires flarum-webpack-config 3.1.0, so you don't end up with two copies. Its README now also explains the duplicate
regenerate error some lockfiles run into.
Also fixed since Flarum 2.0
- Lazily loaded chunks from different extensions no longer collide (3.0.5, #5085). Webpack chunk ids are only unique within one build, so two extensions could load each other's files. Each build now has its own chunk store. Thanks to @datlechin for the analysis.
- A module imported lazily in one place and directly in another is registered under the right chunk (3.0.6, #5102).
export default <expression> is registered under the right name (3.0.7, #5234). For example, export default (native: boolean) => … was registered under the parameter's name.
What to do when you next update
Upgrade both packages together, and if your package.json declares typescript, move it to ^5.9.3:
yarn add --dev flarum-webpack-config@^3.1.0 @flarum/jest-config@^2.1.1 typescript@^5.9.3
# or
npm install --save-dev flarum-webpack-config@^3.1.0 @flarum/jest-config@^2.1.1 typescript@^5.9.3
Leave out @flarum/jest-config if you don't use it. Do keep typescript declared in your own package.json: Yarn 2+ and pnpm don't let a package run a command it doesn't declare.
Why TypeScript 5.9, and not 7?
TypeScript 7 is out, but it can't read the configuration Flarum 2 extensions are built with. flarum-tsconfig sets "moduleResolution": "Node", and most extensions' own tsconfig.json set baseUrl for their flarum/* paths. TypeScript 6 deprecated both, and TypeScript 7 removes them. Moving past 5.9 would mean changing flarum-tsconfig and every extension's tsconfig.json at once, which isn't something to slip into a tooling update. TypeScript 5.9 is the newest version that works with the setup every Flarum 2 extension has today, so that's where we've stopped for now. Going further needs a new flarum-tsconfig and a migration path for extensions, so it will be handled separately.
If your extension already runs on TypeScript 6 or 7 because its own tsconfig.json uses another module resolution and no baseUrl, you can keep it: Flarum CLI 3.0.15 leaves it alone.
Optional: Prettier 3 and webpack-cli 7
Flarum's bundled extensions, and most FoF extensions, now use Prettier 3 (^3.9.10) and webpack-cli 7 (^7.2.3). Neither is required, but if you'd like to match:
- after upgrading Prettier, run
yarn format once. Prettier 3 formats a few things slightly differently, and otherwise format-check will flag them;
- webpack-cli 7 needs Node.js 20.9 or later. In our testing, it produced exactly the same bundles as earlier versions.
Flarum CLI 3.0.15
Update with npm install -g @flarum/cli@latest.
Better upgrades from Flarum 1.x. flarum-cli upgrade 2.0 has had a lot of work since Flarum 2.0 came out, much of it from running it on real 1.x extensions:
- it brings an extension's build tooling to the versions above, including TypeScript 5.9. Earlier CLI versions brought TypeScript down to 4.9 during the upgrade, so if you used one, check your
typescript version;
- tests move to PHPUnit 12, and each model gets a factory written from its migrations;
- admin settings, permissions and pages are registered with
Extend.Admin;
- when a step can't upgrade a file, it tells you which one, and running the command again resumes where it stopped.
Check an extension you've already upgraded. flarum-cli upgrade 2.0 --check runs every step on a temporary copy of your last commit and reports what each one would change, without touching your extension. It's useful for extensions upgraded with an earlier CLI version, or by hand. Add --json to see each change in full.
New extensions created with flarum-cli init start on all of the above.
Coming next: Yarn 4
We plan to move Flarum's own development from Yarn 1 to Yarn 4 soon. You don't need to do anything for this now. We'll post again when it happens, with anything extension developers need to know.
Most FoF extensions have already moved to the new tooling, and we tested these upgrades against more than 20 real third-party extensions before release. If something doesn't go smoothly for yours, tell us below.