I try to implement SyntaxHighlighter using react and webpack.
I install it via npm.
npm install --save syntaxhighlighter
It install perfectly. Now the problem is how to import it properly.
I've tried like this:
import SyntaxHighlighter from 'syntaxhighlighter';
But it doesn't work, Chrom console reports the error like:
TypeError: Cannot assign to read only property 'exports' of object '#'
How can I use syntaxHighlighter with webpack and react?
npm install react-syntax-highlighter
import SyntaxHighlighter from "react-syntax-highlighter";
import { aStyle } from "react-syntax-highlighter/styles/hljs-or-prism";
<SyntaxHighlighter language="yourLanguage" style={aStyle}>
{yourCode}
</SyntaxHighlighter>
import React from "react";
import ReactDOM from "react-dom";
import SyntaxHighlighter from "react-syntax-highlighter";
import { docco } from "react-syntax-highlighter/styles/hljs";
function App() {
return (
<div className="App">
<SyntaxHighlighter language="javascript" style={docco}>
{console.log('Hello world!...');}
</SyntaxHighlighter>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With