Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@UncleJart
Copy link
Contributor

@UncleJart UncleJart commented Oct 22, 2025

List of changes:

  • Fixed refractor imports for v5.0.0
  • Downgraded lint-staged to latest Node 16 compatible version
  • Added cross-env so npm scripts with env vars definitions don't fail on Windows
  • Updated webpack to v5 with ESM libs support (required for proper refractor imports processing), updated webpack/babel plugins to latest versions with Node 16 support
  • Migrated webpack config to be v5 compatible
  • Updated Jest config to work with now ESM only refractor 5 - it was necessary to add mappings for refractor exports and add refractor and all of its deps to transformIgnorePatterns. All tests passed.
  • Added engines section to package.json with Node 16.20.2 requirement
  • All scripts from package.json were checked to run properly on Win 11 with Node 16.20.2
  • There is a warning during webpack build about changing NODE_ENV with DefinePlugin - its OK for webpack 5 and can be ignored

Briefly checked default Vite + React template with examples from react-syntax-highlighter Readme, seems like everything works OK - dev/prod build passed. Would be great if someone else checks it, also with webpack based project.

How to check (npm):

  • In package.json replace react-syntax-highlighter with the following version
"react-syntax-highlighter": "git+https://github.com/UncleJart/react-syntax-highlighter.git#aea2ad57526443240bbd321aabb298f7a1d01b68"
  • Run npm i
  • Run dev/prod build and check the results

@abentele
Copy link

abentele commented Oct 23, 2025

tested within my vitejs (rolldown-vite) based application. Works for me, no errors in browser console or in the application any more.
Remarks: I only tested a small part of this lib, this is no complete review.

The relevant code in my app is:

import { docco } from "react-syntax-highlighter/dist/esm/styles/hljs"
const SyntaxHighlighter = React.lazy(() => import("react-syntax-highlighter"))
[...]
                                    <SyntaxHighlighter language="xml" style={docco}>
                                        {transaction.originalFileContent!}
                                    </SyntaxHighlighter>

Some dependencies in my app's package.json:

...
        "@vitejs/plugin-react": "^5.0.4",
        "vite": "npm:[email protected]",
        "react": "19.2.0",
...

To integrate the pull request in my app I used this commands:

git clone https://github.com/UncleJart/react-syntax-highlighter.git
cd react-syntax-highlighter
git checkout v16-fix-refractor-imports
npm install
npm run build

# and then in my app folder:
npm install --no-save <absolute-path-of-the-above-repo>/react-syntax-highlighter

@UncleJart
Copy link
Contributor Author

UncleJart commented Oct 23, 2025

npm install in package dir already runs build, so it is not necessary to run it separately:

"prepare": "npm run build-styles-hljs && npm run build-languages-hljs && npm run build-styles-prism && npm run build-languages-prism && npm run build"

Also, if package cloned locally, you can use npm link.

@abentele
Copy link

Since npm link requires sudo privileges on macOS, I used the "npm install --no-save" variant instead. It's easier for a one-time test.

@UncleJart
Copy link
Contributor Author

UncleJart commented Oct 23, 2025

Added to PR description instructions how package can be installed directly from github (for npm).

Checked on webpack 5 based project which uses hljs imports - everything builds/works as expected. These are not refractor imports, but still.

import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
import xml from 'react-syntax-highlighter/dist/esm/languages/hljs/xml';
import sql from 'react-syntax-highlighter/dist/esm/languages/hljs/sql';
import vs from 'react-syntax-highlighter/dist/esm/styles/hljs/vs';

const Component = () => {
...
<div className="query-body">
      {contentType
        ? (<SyntaxHighlighter language={contentType} style={vs} wrapLongLines>{command}</SyntaxHighlighter>)
        : (<pre><code>{command}</code></pre>)
      }
    </div>
...
}

@jonepo
Copy link

jonepo commented Oct 23, 2025

This also works for my React project now that uses Vite 6.4.1. In addition, I'm using the dev dependency "@types/react-syntax-highlighter": "^15.5.13". The code I'm using this library in my component is as follows:

import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';

export const MyComponent = () => {
  ...
	return (
		<SyntaxHighlighter
			PreTag='div'
			language={match[1]}
			style={vscDarkPlus}
			className={'text-content-codeblock-inner'}
			{...props}>
			{children}
		</SyntaxHighlighter>
	);
};

@skvark
Copy link

skvark commented Oct 23, 2025

The fix works on my project as well which uses rsbuild:

import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { oneLight, oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';

export const MyComponent = () => {
  ...
	return (
        <SyntaxHighlighter
          language={language}
          style={isDark ? oneDark : oneLight}
        />
	);
};

@elchininet
Copy link

This fixes the errors in one of my projects that got broken after the update to [email protected].

@sacummings91
Copy link

Tried this in our vite 6 project and it fixes the build issue!

@simmerer
Copy link
Collaborator

Thank you so much @UncleJart and everyone for testing. I'll get this out shortly as 16.1.0

@simmerer simmerer merged commit c71356f into react-syntax-highlighter:master Oct 28, 2025
1 check passed
@simmerer
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants