react-native - React Native Upgrade-jest transformIgnorePatterns 不再工作?
问题描述
我最近升级到 RN 0.56.0。我的应用程序运行良好,但是当我运行测试时,我收到错误提示我有未以纯 javascript 发布的 3rd 方模块,但即使在应用transformIgnorePatterns
到有问题的模块之后,babel 似乎也不起作用正确。
Test suite failed to run
SyntaxError: /Users/cobb/develop/my-app/node_modules/react-navigation-props-mapper/index.js: Unexpected token (10:13)
8 |
9 | if (!SecondOrderWrapperComponent) {
> 10 | return <WrappedComponent {...screenProps} {...propsExceptScreenProps} {...params} />;
| ^
11 | } else {
12 | return (
13 | <SecondOrderWrapperComponent
at Parser.raise (node_modules/@babel/parser/lib/index.js:3898:15)
at Parser.unexpected (node_modules/@babel/parser/lib/index.js:5227:16)
at Parser.parseExprAtom (node_modules/@babel/parser/lib/index.js:6307:20)
at Parser.parseExprSubscripts (node_modules/@babel/parser/lib/index.js:5903:21)
at Parser.parseMaybeUnary (node_modules/@babel/parser/lib/index.js:5882:21)
at Parser.parseExprOps (node_modules/@babel/parser/lib/index.js:5791:21)
at Parser.parseMaybeConditional (node_modules/@babel/parser/lib/index.js:5763:21)
at Parser.parseMaybeAssign (node_modules/@babel/parser/lib/index.js:5710:21)
at Parser.parseExpression (node_modules/@babel/parser/lib/index.js:5663:21)
at Parser.parseReturnStatement (node_modules/@babel/parser/lib/index.js:7476:28)
我实际上已经react-navigation-props-mapper
忽略了(或者我是这么认为的),但现在无论我做什么,我都会看到同样的错误。
我的.babelrc:
{
"presets": [
"react-native"
],
"env": {
"development": {
"plugins": [
"@babel/transform-react-jsx-source",
"transform-es2015-modules-commonjs"
]
},
"test": {
"plugins": [
"@babel/transform-react-jsx-source",
"transform-es2015-modules-commonjs"
]
}
},
"ignore": [
"node_modules/aws-sdk"
]
}
和 package.json:
{
"name": "pensive-app",
"version": "0.1.0",
"private": true,
"devDependencies": {
"@babel/core": "^7.0.0-beta.55",
"babel-core": "^7.0.0-0",
"babel-eslint": "^8.2.2",
"babel-jest": "^23.4.2",
"babel-preset-react-native": "^5.0.1",
"eslint": "^4.18.2",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"jest": "^22.4.2",
"jest-fetch-mock": "^1.4.2",
"jest-react-native": "^18.0.0",
"patch-package": "^5.1.1",
"postinstall-postinstall": "^1.0.0",
"react-test-renderer": "16.2.0"
},
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios",
"test": "node node_modules/jest/bin/jest.js",
"eslint": "./node_modules/.bin/eslint App.js src/**/*.js",
"postinstall": "patch-package"
},
"jest": {
"preset": "react-native",
"setupFiles": [
"./setupJest.js"
],
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"!**/node_modules/**",
"!**/vendor/**"
],
"transformIgnorePatterns": [
"node_modules/(?!react-navigation-props-mapper)/"
]
},
"dependencies": {
"amazon-cognito-identity-js": "^2.0.19",
"aws-amplify": "^1.0.4",
"aws-sdk": "^2.282.1",
"password-validator": "^4.1.1",
"prop-types": "^15.6.1",
"react": "16.4.1",
"react-native": "0.56.0",
"react-native-keyboard-aware-scroll-view": "^0.4.4",
"react-native-loading-spinner-overlay": "^0.5.2",
"react-native-phone-input": "^0.2.1",
"react-native-swipeout": "^2.3.3",
"react-native-tag-select": "^2.0.0",
"react-native-vector-icons": "^4.6.0",
"react-navigation": "1.5.11",
"react-navigation-props-mapper": "^0.2.0",
"react-redux": "^5.0.7",
"redux": "^3.7.2"
}
}
如果我正确阅读了该错误,看起来 jest 正在尝试做某事但失败了,这告诉我我的 .babelrc 中可能有一些错误配置。我可以看到这个新的 babel 有很多变化,这仍然是“测试版”。也许我应该坚持使用 RN 0.55 一段时间?
解决方案
推荐阅读
- c# - implement datatable js in Asp.Net API server side processing
- powershell - 如何使用 Powershell 在 Azure AD 应用程序中为隐式流启用访问令牌
- sql - 通过生成查询从 DataFrame 中获取数据并插入到 SQL 表中的多行中
- ios - 如何在 iOS 13 中更改状态栏 Alpha?
- reactjs - Mobx 如何等到 Promise
完成然后运行不同的功能 - javascript - C# ToDictionary 的 JavaScript 等价物
- powershell - 我在创建唯一目录和文件时做错了什么,同时使用 PowerShell 验证目录和文件名是唯一的?
- node.js - 重新启动 EC2 现在我无法调用我的快速 API
- python-3.x - 如何舍入小数类型
- xaml - Xamarin 表单样式 - 支持多种目标类型