sashang
sashang

Reputation: 12184

unexpected token in javascript

I'm getting this error:

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;

This is my babel config:

babel: {
        presets: [
            ["@babel/preset-env", {
                "targets": "> 0.25%, not dead",
                "modules": false,
                // This adds polyfills when needed. Requires core-js dependency.
                // See https://babeljs.io/docs/en/babel-preset-env#usebuiltins
                "useBuiltIns": "usage",
            }]
        ],
    }

This is how bable config is used:

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

How can I resolve the compiler error? I just want to load some static html content.

Upvotes: 0

Views: 60

Answers (2)

Michael
Michael

Reputation: 5038

Your Div needs a closing tag, it is not an element that can be written <div\> rather make sure to write <div ....></div>

Upvotes: 0

molamk
molamk

Reputation: 4116

You need to include @babel/preset-react in your babel config for it to compile JSX

Try this

In your command line

npm install --save-dev @babel/preset-react

In your babel config

{
  "presets": ["@babel/preset-react"]
}

Upvotes: 2

Related Questions