I thought I would post my experience facing a rare but hard-to-debug react native class-transformer issue.
Much has already been said about how to use set up class-transformer in react-native, a much-needed library if we are to deal conveniently with complex types like unserialised javascript Dates being returned from an API. Long story short, you need to set an array of niche babel plugins to get those decorators to work, my set-up in the babel.config.js file is the following:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'module:react-native-dotenv',
{
moduleName: '@env',
allowUndefined: true,
},
],
'react-native-reanimated/plugin',
'babel-plugin-transform-typescript-metadata',
'@babel/plugin-transform-flow-strip-types',
['@babel/plugin-proposal-decorators', {legacy: true}],
],
};
Everything was working well until I tried to use class-transformer to type my JSON object stored in Async Storage (to create state persistence between usages) when I got this issue:
And on the console:
ERROR TypeError: undefined is not a function, js engine: hermes
LOG Running "App" with {"rootTag":251,"initialProps":{}}
ERROR Invariant Violation: "App" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes