[英]Optional-Chaining does not work in create-react-app
在create-react-app
項目中,我在 `.babelrc 中使用@babel/plugin-proposal-optional-chaining
但是,我有這個錯誤: Module parse failed: Unexpected token (22:16) You may need an appropriate loader to handle this file type.
這是我所有的 babel 依賴項:
{
"dependencies": {
"@babel/core": "^7.9.0",
"@babel/node": "^7.8.7",
"@babel/plugin-external-helpers": "^7.8.3",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/plugin-proposal-json-strings": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.9.5",
"@babel/plugin-proposal-optional-chaining": "^7.9.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.8.3",
"@babel/plugin-transform-async-to-generator": "^7.8.3",
"@babel/plugin-transform-modules-commonjs": "^7.9.0",
"@babel/plugin-transform-react-constant-elements": "^7.9.0",
"@babel/plugin-transform-react-inline-elements": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/polyfill": "^7.8.7",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-inline-react-svg": "^1.1.1"
}
}
為了讓它工作,我還需要什么?
你只需要確保你已經安裝了react-scripts
3.3.0+版本,因為它已經內置了可選的鏈接:
const obj = { a: `Hello` };
// Hello World
const App = () => {
return (
<>
{obj?.a}
{obj?.b ?? ` World`}
</>
);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.