vihanb / babel-plugin-wildcard

Wildcard imports import a directories JS files
MIT License
186 stars 27 forks source link

Does not work with React Native #45

Open kendallroth opened 2 years ago

kendallroth commented 2 years ago

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: { ... } } ],
  ],
};
JustinRohweller commented 2 years ago

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.

Jaybee4real commented 1 year ago

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!