Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript中的意外标记_Javascript_Reactjs_Babeljs - Fatal编程技术网

javascript中的意外标记

javascript中的意外标记,javascript,reactjs,babeljs,Javascript,Reactjs,Babeljs,我得到了这个错误: ERROR in ./src/Client/privacy-policy.js Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: /home/sashan/code/titan/src/Client/privacy-policy.js: Unexpected token (7:17) 5 | const PrivacyPolicy = createRea

我得到了这个错误:

ERROR in ./src/Client/privacy-policy.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/sashan/code/titan/src/Client/privacy-policy.js: Unexpected token (7:17)


   5 | const PrivacyPolicy = createReactClass({
   6 |     render() {
>  7 |         return ( <div dangerouslySetInnerHTML={ {__html: htmlContent} } />);
     |                  ^
   8 |     }
   9 | });
  10 | export default PrivacyPolicy;
以下是bable配置的使用方式:

 {
     test: /\.js$/,
     exclude: /node_modules/,
     use: {
        loader: 'babel-loader',
        options: CONFIG.babel
      },
 },

如何解决编译器错误?我只想加载一些静态html内容。

您需要在babel配置中包含,以便它编译JSX

试试这个

在命令行中 在你的babel配置中
您需要在babel配置中包含,以便它编译JSX

试试这个

在命令行中 在你的babel配置中
您的Div需要一个结束标记,它不是一个可以编写的元素,而是确保编写一个结束标记。您的Div需要一个结束标记,它不是一个可以编写的元素,而是确保编写一个JSX语法,而不是JavaScript。您还需要对其进行传输。@后面的逗号是可选的,但允许您在传输react jsx时使用。这是jsx语法,而不是JavaScript。您还需要对其进行传输。@尾随逗号是可选的,但允许您在传输react jsx时使用。不在jsx中使用。标记可以自动关闭,因此
在JSX中也是无效的。标记可以自动关闭,因此
也是有效的
 {
     test: /\.js$/,
     exclude: /node_modules/,
     use: {
        loader: 'babel-loader',
        options: CONFIG.babel
      },
 },
npm install --save-dev @babel/preset-react
{
  "presets": ["@babel/preset-react"]
}