This is a demo app of FBT used in Next.js with Typescript. See it in action: nextjs-fbt.vercel.app
FBT itself works great, but its installation requires a few tricks.
When you run npm install fbt
to install the package, it fails with this error:
npm ERR! Could not resolve dependency:
npm ERR! peer react@"0.12.0 - 17.x.x" from fbt@1.0.0
npm ERR! node_modules/fbt
npm ERR! fbt@"*" from the root project
It is a known issue, before it is fixed in the new version, it needs to be fixed manually in package.json
:
"overrides": {
"fbt@1.0.0": {
"react": "18.2.0"
}
}
In addition to two mandatory plugins (babel-plugin-fbt
and babel-plugin-fbt-runtime
), you need to setup Babel so that this error does not occur:
Error: Line 27 Column 11: fbt is not bound. Did you forget to require('fbt')?
Why this error happens and one way how to fix it is explained here.
A simpler fix due to @adeira/babel-preset-adeira
is used in this project:
Lines 1 to 7 in 746a6a6
Collecting and translating with FBT is a three step process for which three NPM scripts are prepared:
Lines 13 to 16 in 746a6a6
I recommend to run them all at once with npm run fbt
.
If you use npm run fbt
then postfbt
script will be executed automatically to format generated files with Prettier. I find it useful for git diff
, code review etc to have those files nicely formatted.