πŸš€ UllrichLumina

Nodejs 1701 Gatsby error - digital envelope routinesunsupported  ERROSSLEVPUNSUPPORTED duplicate

Nodejs 1701 Gatsby error - digital envelope routinesunsupported ERROSSLEVPUNSUPPORTED duplicate

πŸ“… | πŸ“‚ Category: Node.js

Developers often encounter perplexing errors that halt their progress, and one particularly common and frustrating issue for those working with Gatsby.js on newer Node.js versions is the Node.js 17.0.1 Gatsby error - “digital envelope routines::unsupported … ERR_OSSL_EVP_UNSUPPORTED”. This specific error message, frequently seen as a duplicate across forums and issue trackers, signals a deeper compatibility conflict rather than a simple code bug. It typically manifests during the build process of a Gatsby site, leaving developers puzzled and projects stalled. Understanding the root cause of this error is crucial for effective troubleshooting and maintaining a smooth development workflow, especially as Node.js and its underlying dependencies rapidly evolve. This guide will meticulously break down the problem, explore its origins, and provide robust, actionable solutions to get your Gatsby projects back on track.

Understanding the “digital envelope routines::unsupported” Error

The “digital envelope routines::unsupported” error, accompanied by the ERR_OSSL_EVP_UNSUPPORTED code, is a direct consequence of a significant shift in cryptography libraries. Specifically, it points to an incompatibility between Node.js versions 17 and above, and the OpenSSL 3.0 library that these newer Node.js releases bundle. OpenSSL 3.0 introduced more stringent security policies and deprecated older, less secure cryptographic algorithms, including MD4, which some legacy systems or dependencies might still implicitly rely on.

When Gatsby builds a project, it leverages various underlying tools and dependencies, including Webpack, which in turn might use Node.js’s built-in crypto module. If any part of this dependency chain attempts to use a deprecated algorithm that OpenSSL 3.0 no longer supports by default, this error surfaces. This isn’t an issue specific to Gatsby’s core; rather, it’s a systemic problem arising from the interaction between newer Node.js versions, their bundled OpenSSL library, and potentially older packages within your project’s dependency tree. This situation highlights the critical need for developers to be aware of the underlying infrastructure changes that can impact their development environments.

The OpenSSL 3.0 Impact

OpenSSL 3.0 represents a major update to the widely used cryptographic software library. Its primary goal was to enhance security by removing or disabling outdated and potentially vulnerable algorithms. While this is a positive step for overall security posture, it creates a backward compatibility challenge for applications that haven’t updated their cryptographic practices. Node.js 17.x was among the first versions to ship with OpenSSL 3.0, immediately exposing projects like Gatsby that rely heavily on Node.js’s runtime and its internal modules to this change.

The error specifically indicates that a “digital envelope routine” is unsupported. Digital envelopes are methods of encrypting data using a combination of symmetric and asymmetric encryption. The “unsupported” part means that the specific cryptographic method or algorithm being requested by a dependency is no longer permitted by OpenSSL 3.0’s default security policy. This often occurs in legacy code paths within webpack, or other build tools, that might be using older hashing algorithms or encryption methods. For more in-depth technical details on OpenSSL 3.0 changes, refer to the official OpenSSL 3.0 Migration Guide.

Why Node.js 17 and Gatsby?

The prevalence of this error with Node.js 17 and Gatsby stems from the timing of Node.js 17’s release, which bundled OpenSSL 3.0, and Gatsby’s reliance on Node.js for its build processes. Gatsby, being a static site generator, uses Node.js extensively for compiling React components, processing data, and optimizing assets. When Node.js 17 became available, many developers eagerly upgraded to take advantage of new features or performance improvements. However, this upgrade inadvertently brought in the OpenSSL 3.0 compatibility challenge.

The issue isn’t exclusive to Gatsby; other Node.js-based frameworks and tools can also encounter it. However, Gatsby’s complex build pipeline, which often involves webpack and numerous plugins, increases the likelihood of hitting a dependency that triggers this error. For instance, some older versions of webpack or its loaders might have internal components that use deprecated OpenSSL algorithms, leading to the “digital envelope routines::unsupported” error during the Gatsby build. This problem persists in Node.js 18+ as well, as they continue to use OpenSSL 3.x, making the solutions discussed here relevant for newer Node.js versions too.

Immediate Solutions and Workarounds

Addressing the Node.js 17.0.1 Gatsby error - “digital envelope routines::unsupported … ERR_OSSL_EVP_UNSUPPORTED” often requires a quick fix to unblock development. While long-term solutions involve dependency updates, immediate workarounds can help you continue building and deploying your Gatsby projects. The most common and effective solution involves adjusting Node.js’s behavior regarding its cryptographic policies. This allows OpenSSL 3.0 to temporarily permit the use of older algorithms, bypassing the immediate error. It’s important to understand that these are workarounds and should be used with an awareness of their implications, particularly in production environments where security is paramount.

For many developers, the fastest way to resolve this error is by setting an environment variable that instructs Node.js to use a “legacy” OpenSSL provider. This essentially tells the runtime to be more lenient with older cryptographic routines. While this method gets your build working, it’s crucial to consider the security implications, as it re-enables algorithms that OpenSSL 3.0 intentionally deprecated due to known vulnerabilities or weaknesses. Therefore, this should be seen as a temporary measure while you work towards a more permanent fix by updating your project’s dependencies.

The NODE_OPTIONS Environment Variable

The most widely adopted solution for this error is to set the NODE_OPTIONS environment variable to enable the OpenSSL legacy provider. This instructs Node.js to load a module that provides support for the deprecated cryptographic algorithms, allowing your Gatsby build to proceed without error. This method is effective for both local development and CI/CD environments.

To implement this, you can preface your Node.js commands with the environment variable. Here’s how you can do it:

  1. For a single command: NODE_OPTIONS=--openssl-legacy-provider npm run build or NODE_OPTIONS=--openssl-legacy-provider gatsby develop This is useful for quick tests or one-off builds.
  2. For your shell session (macOS/Linux): export NODE_OPTIONS=--openssl-legacy-provider Then run your Gatsby commands as usual (e.g., gatsby develop, npm run build). This setting will persist for the current terminal session.
  3. For your shell session (Windows Command Prompt): set NODE_OPTIONS=--openssl-legacy-provider Similar to Linux, this sets the variable for the current session.
  4. For your shell session (Windows PowerShell): $env:NODE_OPTIONS="--openssl-legacy-provider" This sets the variable for the current PowerShell session.
  5. In your package.json scripts: You can modify your scripts to include this variable, making it part of your project’s standard commands: ``` “scripts”: { “develop”: “NODE_OPTIONS=–openssl-legacy-provider gatsby develop”, “build”: “NODE_OPTIONS=–openssl-legacy-provider gatsby build”, “serve”: “NODE_OPTIONS=–openssl-legacy-provider gatsby serve” }
    
     This is often the most convenient method for team environments, ensuring everyone uses the same workaround.
    

While effective, remember that this workaround compromises the enhanced security provided by OpenSSL 3.0. It’s crucial to understand that you are re-enabling older, potentially less secure cryptographic methods. Therefore, while suitable for development, consider deeper dependency updates for production builds where security is paramount.

Downgrading Node.js

Another immediate workaround, particularly if you’re not ready to delve into dependency updates or environment variable configurations, is to downgrade your Node.js version. Node.js versions prior to 17.x, such as Node.js 16.x (which is an LTS - Long Question & Answer :

I am building a [Gatsby](https://www.gatsbyjs.com/) site. I upgraded Node.js to **v17.0.1**, and when I run a build, there is an error:
Error: digital envelope routines::unsupported opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ], library: 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED' 

If I downgrade it to v16, it works fine, and the build will be successful. How can I fix this?

From googling, this may be a similar issue: Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt #48

This might help. Add these scripts in the package.json file.

React:

"scripts": { "start": "export SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start", "build": "export SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts build" } 

If you are on Windows and you are using React.js you can use set instead of export in your scripts as follows:

"scripts": { "start": "set SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start", "build": "set SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts build" } 

or

"scripts": { "start": "react-scripts --openssl-legacy-provider start", "build": "react-scripts --openssl-legacy-provider build", } 

Vue.js:

"scripts": { "serve": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve", "build": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build", "lint": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service lint" }, 

If you are on Windows and you are using Vue.js you can use set instead of export in your scripts as follows:

"scripts": { "serve": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve", "build": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build", "lint": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service lint" }, 

or

"scripts": { "serve": "vue-cli-service --openssl-legacy-provider serve", "build": "vue-cli-service --openssl-legacy-provider build", "lint": "vue-cli-service --openssl-legacy-provider lint" }, 

Angular:

"scripts": { "start": "set NODE_OPTIONS=--openssl-legacy-provider && gulp buildDev && ng serve ", "publish": "set NODE_OPTIONS=--openssl-legacy-provider && gulp build && ng build --prod", }, 

🏷️ Tags: