-
Notifications
You must be signed in to change notification settings - Fork 84
Description
Fix for digital envelope routines::unsupported Error in Node.js 23+
Description
When running npm run SpStart on Node.js versions 17 or higher (e.g., Node.js 23.11.0), users may encounter the following error due to OpenSSL 3.0 deprecating certain cryptographic algorithms used by Webpack in react-scripts:
Error: error:0308010C:digital envelope routines::unsupported
This issue occurs because Webpack's default MD4 hash function is not supported in newer Node.js versions. This guide provides a solution to ensure compatibility.
Solution
To resolve this issue and make the SpStart script work across platforms, including Windows, we recommend using the cross-env package to set the NODE_OPTIONS environment variable.
Steps
Install cross-env:Run the following command in your project directory to install cross-env as a development dependency:
npm install --save-dev cross-env
Update package.json:Modify the SpStart script in package.json to use cross-env for setting NODE_OPTIONS:
"scripts": {
"SpStart": "cross-env NODE_OPTIONS=--openssl-legacy-provider react-scripts start"
}
Run the script:Execute the SpStart script as usual:
npm run SpStart
Why This Works
The NODE_OPTIONS=--openssl-legacy-provider flag enables Node.js to use the legacy OpenSSL provider, which supports the deprecated MD4 hash function required by older versions of react-scripts. The cross-env package ensures this environment variable is set correctly across different operating systems, including Windows, where direct environment variable syntax may fail.
Alternative Solutions
Downgrade Node.js: Use Node.js 18 LTS, which uses OpenSSL 1.x and avoids this issue. Install it via Node.js website or a version manager like nvm:nvm install 18
nvm use 18
Upgrade react-scripts: Update to react-scripts@5.x or higher, which uses modern hashing algorithms compatible with Node.js 23:npm install react-scripts@latest
Note: This may introduce breaking changes, so test thoroughly.
Patch Webpack: Use craco to configure Webpack to use SHA-256 instead of MD4. Refer to the Create React App documentation for details.
Recommendations for Future Users
Add cross-env to the project's dependencies and update the SpStart script as shown above to ensure compatibility with Node.js 17+.
Consider upgrading react-scripts for a long-term fix, but verify compatibility with your project.
If using Node.js 23+, always include cross-env or set NODE_OPTIONS manually in your environment.
Additional Notes
If you encounter issues after applying this fix, clear the npm cache and reinstall dependencies:npm cache clean --force
npm install
For further assistance, include your Node.js version, react-scripts version, and any error logs when reporting issues.
by @LuxusIX and Grok AI