react-native - 对于 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)-(.*)+)"
]
推荐阅读
- python - 如何在不使用python中的正则表达式的情况下计算连字符的单词
- token - 如何在 ANTLR4 中标记多行中的单词
- ios - View Controller 以模式呈现,但 segue 是 Show Segue
- ios - 如何在我的 iOS 应用中实现 Firebase 以上传/下载 SceneKit 文件?
- angularjs - ui-grid textarea 编辑后不关闭
- sql - 在插入期间避免重复
- css - SVG动画中的关键帧取消前一个关键帧
- css - 如何使 div 响应指定的高度
- amazon-web-services - 在 AWS-CLI 中使用上传存档时需要帮助了解“InvalidParameterValueException: Invalid Content-Length”错误
- usb - 如何在 i.MX7 上构建 Yocto hddimg 以从 U 盘启动