简体   繁体   中英

error: index.js: [BABEL]: Cannot find module 'node:fs' in react-native

I am trying to run react native app on Andriod but I am getting this error presets: ['module:metro-react-native-babel-preset'], , Could someone please help me to how to resolve this issue.

const {getDefaultConfig} = require('metro-config');
module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
};
module.exports = (async () => {
  const {
    resolver: {sourceExts, assetExts},
  } = await getDefaultConfig();
  return {
    transformer: {
      babelTransformerPath: require.resolve('react-native-svg-transformer'),
    },
    resolver: {
      assetExts: assetExts.filter(ext => ext !== 'svg'),
      sourceExts: [...sourceExts, 'svg'],
    },
  };
})();
  1. Please check metro-react-native-babel-preset dependency was installed in your package.json file.

    If not, install it using this command: npm i metro-react-native-babel- preset --save-dev

  2. Please check babel.config.js file

    There should be this code:

 module.exports = { presets: ['module:metro-react-native-babel-preset'], .... }

just update node to the latest version

using sudo n latest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM