How to fix “error:0308010C:digital envelope routines::unsupported” when creating a React project in IntelliJ IDEA?
I’m encountering the following error when creating a default React project in IntelliJ IDEA:
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:130:10)
at module.exports (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/util/createHash.js:135:53)
at NormalModule._initBuildHash (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:417:16)
at handleParseError (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:471:10)
at /Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:503:5
at /Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:358:12
at /Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:373:3
at iterateNormalLoaders (/Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
at iterateNormalLoaders (/Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
/Users/user/Programming Documents/WebServer/untitled/node_modules/react-scripts/scripts/start.js:19
throw err;
^
I understand this might be related to a recent webpack issue, as mentioned in their GitHub repository. What causes this error and how can I resolve it when setting up a new React project?
This error occurs due to Node.js version compatibility issues with webpack’s cryptographic hash functions. The most effective solutions are to either upgrade Node.js to a compatible version or configure webpack to use legacy hash algorithms that work with your current Node.js installation.
Contents
- Understanding the Error
- Root Causes
- Multiple Solutions
- IntelliJ IDEA Specific Considerations
- Prevention Tips
- Troubleshooting Steps
Understanding the Error
The error error:0308010C:digital envelope routines::unsupported is a Node.js cryptographic error that occurs when webpack tries to create hash functions during the build process. This error typically manifests when:
- Using Node.js 17+ with older webpack versions (pre-5.61.0)
- Using Node.js 16.13.0+ with older versions of webpack plugins
- There’s an OpenSSL version incompatibility between Node.js and the webpack build tools
The stack trace shows the error originates from webpack’s createHash.js file, specifically when it attempts to use cryptographic hash algorithms that aren’t supported by the current Node.js version.
Root Causes
Several factors contribute to this error:
- Node.js Version Mismatch: Using Node.js 17+ with webpack versions that don’t support the new cryptographic requirements
- OpenSSL Version Conflicts: Different OpenSSL versions between Node.js and system libraries
- Outdated Webpack Dependencies: React projects created with older webpack versions
- Environment Variables: Missing Node.js environment variables that configure legacy crypto support
- IntelliJ IDEA Configuration: IDE-specific settings or terminal configurations that affect Node.js execution
The error specifically occurs because webpack is trying to use node:internal/crypto/hash routines that were changed or deprecated in newer Node.js versions.
Multiple Solutions
Solution 1: Upgrade Node.js
The most reliable solution is to upgrade Node.js to a version that fully supports webpack’s requirements:
- Download and install Node.js 18.x or later from nodejs.org
- Verify the installation:
node --version(should show v18.x or higher) - Reinstall project dependencies:bash
rm -rf node_modules package-lock.json npm install
This solution works because newer Node.js versions include updated OpenSSL support that webpack expects.
Solution 2: Use Legacy Node.js Flag
If you need to keep your current Node.js version, add the legacy flag to enable older crypto routines:
-
For npm scripts: Modify your
package.jsonscripts:json"scripts": { "start": "NODE_OPTIONS=--openssl-legacy-provider react-scripts start", "build": "NODE_OPTIONS=--openssl-legacy-provider react-scripts build", "test": "NODE_OPTIONS=--openssl-legacy-provider react-scripts test" } -
For direct execution: Run commands with the flag:
bashNODE_OPTIONS=--openssl-legacy-provider npm start
-
For IntelliJ IDEA: Configure the Node.js interpreter in IDE settings or add the flag to your run configuration.
Solution 3: Update Dependencies
Update your project’s webpack and related dependencies to compatible versions:
-
Update
react-scriptsto the latest version:bashnpm install react-scripts@latest
-
Update webpack and related packages:
bashnpm install webpack@latest webpack-cli@latest
-
Check for outdated peer dependencies:
bashnpm outdated npm update
Solution 4: Modify Webpack Configuration
If you have a custom webpack configuration, modify the hash creation settings:
-
In your
webpack.config.js, add or modify thecreateHashconfiguration:javascriptmodule.exports = { // ... other configurations optimization: { runtimeChunk: 'single', splitChunks: { chunks: 'all', cacheGroups: { vendors: { test: /[\\/]node_modules[\\/]/, name: 'vendors', chunks: 'all', }, }, }, }, // Add this to handle the crypto issue output: { hashFunction: 'sha256', hashDigest: 'hex', hashDigestLength: 20, } }; -
For TypeScript projects, ensure your
tsconfig.jsonincludes the necessary webpack types.
IntelliJ IDEA Specific Considerations
When working in IntelliJ IDEA, consider these IDE-specific solutions:
Configure Node.js Interpreter
- Go to File → Settings → Languages & Frameworks → Node.js and NPM
- Make sure you’re using the correct Node.js version
- Set the Node.js home path to your preferred Node.js installation
Modify Run Configurations
- Go to Run → Edit Configurations
- Select your React app configuration
- In the Environment variables section, add:
NODE_OPTIONS=--openssl-legacy-provider
Use Terminal Integration
- Open the built-in terminal in IntelliJ IDEA (View → Tool Windows → Terminal)
- Run commands with the legacy provider flag:bash
NODE_OPTIONS=--openssl-legacy-provider npm start
Project Structure Considerations
- Ensure
.ideafolder and workspace settings are compatible with your Node.js version - Check for IDE-specific webpack configurations that might conflict
Prevention Tips
To avoid this error in future projects:
-
Use Node Version Manager: Use tools like
nvmornodenvto manage Node.js versions:bashnvm install 18 nvm use 18
-
Specify Node.js Version: In your
package.json:json"engines": { "node": ">=18.0.0" } -
Use Docker: Create a containerized environment with consistent Node.js versions:
dockerfileFROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . CMD ["npm", "start"] -
Regular Updates: Keep dependencies updated by running:
bashnpm audit fix npm update
-
Environment Configuration: Create a
.envfile with Node.js configuration:NODE_OPTIONS=--openssl-legacy-provider
Troubleshooting Steps
If none of the above solutions work, follow these troubleshooting steps:
-
Check Node.js Version:
bashnode --version npm --version
-
Verify OpenSSL Support:
bashnode -e "console.log(process.versions.openssl)" -
Clean Reinstall:
bashrm -rf node_modules package-lock.json npm cache clean --force npm install -
Check for Conflicting Packages:
bashnpm ls webpack npm ls react-scripts -
Test in Different Environment: Try running the project outside IntelliJ IDEA to isolate IDE-specific issues.
-
Check System Environment: Ensure no system-wide Node.js installations are conflicting with your project setup.
Sources
- Node.js Official Documentation - OpenSSL Provider
- Webpack GitHub Issue - Digital Envelope Routines
- Create React App Documentation - Node.js Requirements
- IntelliJ IDEA Node.js Integration Guide
- Node.js Version Compatibility Table
Conclusion
The “digital envelope routines::unsupported” error is a common Node.js compatibility issue that can be resolved through several approaches. The most reliable solutions are either upgrading Node.js to version 18+ or using the --openssl-legacy-provider flag to maintain compatibility with your current setup. For IntelliJ IDEA users, configuring the Node.js interpreter properly and adding the environment variable to run configurations ensures smooth operation. By following the prevention tips and keeping your dependencies updated, you can avoid this issue in future React projects. Always test your solution in a clean environment to ensure the fix works properly before committing to your development workflow.