Skip to content

Instantly share code, notes, and snippets.

@retyui
Last active October 9, 2019 07:45
Show Gist options
  • Save retyui/c55d0ccb6c4ee92e496789f002cb620a to your computer and use it in GitHub Desktop.
Save retyui/c55d0ccb6c4ee92e496789f002cb620a to your computer and use it in GitHub Desktop.
Fix plugin-transform-typescript for fbt

In file node_modules/@babel/plugin-transform-typescript/lib/index.js

For a function isImportTypeOnly add code:

  function isImportTypeOnly({
    binding,
    programPath,
    jsxPragma
  }) {
    for (const path of binding.referencePaths) {
      if (!isInType(path)) {
        return false;
      }
    }

+    // Small fix to stop removing `import fbt from 'fbt';`
+    if (binding.identifier.name === 'fbt') {
+      return false;
+    }

    if (binding.identifier.name !== jsxPragma) {
      return true;
    }
// ...

And add postinstall script to package.json

{
  "name": "fbtDemo",
  "scripts": {
+    "postinstall": "git checkout -f -- :/node_modules",
    "start": "react-native start",
  },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment