简体   繁体   English

reactjs:导入余量后出错

[英]reactjs: getting error after importing headroom

I'm new in react and in my react application I'm trying to use "React Headroom" but after importing I'm getting this SyntaxError "Support for the experimental syntax 'classProperties' isn't currently enabled (10:20):"我是 react 新手,在我的 react 应用程序中,我正在尝试使用“React Headroom”,但在导入后我得到了这个 SyntaxError“当前未启用对实验语法 'classProperties' 的支持(10:20): "

import React from 'react';
import Headroom from 'react-headroom/src';

import './App.css';

function App() {
  return (
    <div className="App">
      <Headroom>
        <nav>
          ...
        </nav>
      </Headroom>
    </div>
  );
}

export default App;导出默认应用程序;

Converting comment to answer将评论转换为答案

Usually you don't import from the src directory.通常你不会从src目录导入。
Try to import from just 'react-headroom' .尝试从'react-headroom'导入。

You need to use the syntax-class-properties plugin .您需要使用syntax-class-properties插件 Install it using使用安装它

yarn add babel-plugin-syntax-class-properties

then add it to your .babelrc :然后将其添加到您的.babelrc

{
    "plugins": ["syntax-class-properties"]
}

Just make sure you are using correct plugins in your.babelrc file只要确保你在你的 .babelrc 文件中使用了正确的插件

 "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      "@babel/plugin-proposal-class-properties"
    ]
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM