import forbidExtraProps from 'prop-types-exact'; ^^^^^^^^^^^^^^^^ SyntaxError: Unexpected identifier
使用airbnb-prop-types
并用Jest测试时出现此错误。我认为Babel版本7的配置存在问题。
依赖关系(来自package.json):
"devDependencies": { "@babel/core": "^7.0.0", "@babel/plugin-proposal-class-properties": "^7.0.0", "@babel/plugin-proposal-decorators": "^7.0.0", "@babel/plugin-proposal-do-expressions": "^7.0.0", "@babel/plugin-proposal-export-default-from": "^7.0.0", "@babel/plugin-proposal-export-namespace-from": "^7.0.0", "@babel/plugin-proposal-function-bind": "^7.0.0", "@babel/plugin-proposal-function-sent": "^7.0.0", "@babel/plugin-proposal-json-strings": "^7.0.0", "@babel/plugin-proposal-logical-assignment-operators": "^7.0.0", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0", "@babel/plugin-proposal-numeric-separator": "^7.0.0", "@babel/plugin-proposal-optional-chaining": "^7.0.0", "@babel/plugin-proposal-pipeline-operator": "^7.0.0", "@babel/plugin-proposal-throw-expressions": "^7.0.0", "@babel/plugin-syntax-dynamic-import": "^7.2.0", "@babel/plugin-syntax-import-meta": "^7.0.0", "@babel/plugin-transform-object-assign": "^7.2.0", "@babel/preset-env": "^7.0.0", "@babel/preset-react": "^7.0.0", "@babel/runtime": "^7.0.0", "@svgr/rollup": "^2.4.1", "airbnb-js-shims": "^2.1.1", "babel-core": "7.0.0-bridge.0", "babel-eslint": "^10.0.1", "babel-jest": "^24.1.0", "babel-preset-airbnb": "^3.2.0", "cross-env": "^5.1.4", "enzyme": "^3.8.0", "enzyme-adapter-react-16": "^1.7.1", "enzyme-to-json": "^3.3.5", "eslint": "^5.7.0", "eslint-config-airbnb": "^17.1.0", "eslint-plugin-import": "^2.14.0", "eslint-plugin-jest": "^22.2.2", "eslint-plugin-jsx-a11y": "^6.1.2", "eslint-plugin-react": "^7.12.3", "gh-pages": "^1.2.0", "identity-obj-proxy": "^3.0.0", "jest": "^24.1.0", "jest-cli": "^24.1.0", "jest-environment-enzyme": "^7.0.1", "jest-enzyme": "^7.0.1", "prettier": "^1.6.1", "react": "^16.4.1", "react-dom": "^16.4.1", "react-scripts": "^2.1.3", "react-test-renderer": "^16.7.0", "regenerator-runtime": "^0.13.1", "rollup": "^0.64.1", "rollup-plugin-babel": "^4.0.1", "rollup-plugin-commonjs": "^9.1.3", "rollup-plugin-node-resolve": "^3.3.0", "rollup-plugin-peer-deps-external": "^2.2.0", "rollup-plugin-postcss": "^1.6.2", "rollup-plugin-url": "^1.4.0", "why-did-you-update": "^1.0.6" }, "dependencies": { "airbnb-prop-types": "^2.11.0", "ajv": "^6.0.0", "classnames": "^2.2.6", "focus-trap-react": "^6.0.0", "lodash": "^4.17.11", "object.assign": "^4.1.0", "object.values": "^1.0.4", "prop-types": "^15.6.1", "react-portal": "^4.2.0" }