vihanb / babel-plugin-wildcard

Wildcard imports import a directories JS files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not work with React Native

kendallroth opened this issue Β· comments

When attempting to use with React Native, I run into an error when attempting to import a bunch of JSON files. Even though the variable is very clearly defined, when I attempt to interact with it it fails gloriously πŸ˜„. It does not appear to be the actual import causing issues, but rather the interactions with it. Any ideas?

// NOTE: '@ts-ignore' is required to avoid TypeScript "invalid path" issues
// @ts-ignore
import * as overrides from '../overrides/*.json';
 ERROR  ReferenceError: Can't find variable: overrides
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

babel.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    ['wildcard', { exts: ['json'] }],
    [ 'module-resolver', { alias: { ... } } ],
  ],
};

For me with .ttf files I think I had the same issue, but it worked when I changed to:
import * as Fonts from "../../assets/fonts/";
Hope this helps someone.

For me with .ttf files I think I had the same issue, but it worked when I changed to: import * as Fonts from "../../assets/fonts/"; Hope this helps someone.

This works for me too, thanks a lot!