微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

对于 react-native 预设的玩笑,transformIgnorePatterns 无法正常工作

如何解决对于 react-native 预设的玩笑,transformIgnorePatterns 无法正常工作

遇到这个错误


    /node_modules/@react-native/polyfills/error-guard.js:14
    type ErrorHandler = (error: mixed,isFatal: boolean) => void;
         ^^^^^^^^^^^^

    SyntaxError: Unexpected identifier

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (node_modules/react-native/jest/setup.js:469:6)

不过,我已经设置了

transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-(native|universal|navigation)-(.*)|@react-native-community/(.*)|@react-navigation/(.*)|bs-platform|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)"
    ]

transformIgnorePatterns": [
      "node_modules"
    ]

我已经正确地设置了 babel

module.exports = function (api) {
  api.cache(true);

  const presets = ['@babel/preset-env','@babel/preset-react'];
  const plugins = ['@babel/plugin-proposal-class-properties'];
  return {
    presets,plugins,};
};

我已经尝试清除缓存。

有人知道吗?

解决方法

@react-native 添加到您的 Jest 配置中。如:

transformIgnorePatterns": [
      "node_modules/(?!(jest-)?@react-native|react-(native|universal|navigation)-(.*)|@react-native-community/(.*)|@react-navigation/(.*)|bs-platform|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)"
    ]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。