如何解决 "Error: error:0308010C:digital envelope routines::unsupported" Nodejs 18 错误

24

请帮我解决我的nuxtjs应用程序问题。在我离开它一段时间没有更新(2个月)后,最近我在应用程序中遇到了eslint冲突。所以在我开始处理这个应用程序后,尝试解决eslint问题变得很困难,所以我不得不将项目迁移到更新的node和eslint版本。做完之后,我已经解决了冲突问题,并且我的项目可以安装依赖项,但现在服务器无法启动,Node现在抛出一个错误,我甚至不知道如何开始修复,我不知道是否有很多其他人在升级他们的nodejs版本后也面对这个问题,但它会抛出关于不支持的哈希函数的错误。enter image description here

下面是终端错误的截图,阻止了我的服务器启动,我已经解决了所有由迁移带来的eslint和语法错误,所以我不知道该怎么办,请帮我,我真的需要帮助。

以下是我的nuxt.config.js文件片段

export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: 'heritage-fd',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' }
    ],
    
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ],
    
    script: [
      {
        src: '~/static/css/bootstrap.min.js',
      },
    ],
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    {src: '~/static/css/bootstrap.min.css', lang: 'scss'},
    {src: '~/assets/scss/custom.scss', lang: 'scss'},
    {src: "~layouts/global.css"},
    {src: '~/static/css/style.css', lang: 'scss'},
    {src: '~/assets/css/main.css'}
    
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
   plugins: [
    "~/plugins/vee-validate.js",
    { src: '~/plugins/persistedState.client.js', ssr: false }
   ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/eslint
    '@nuxtjs/eslint-module',
    'nuxt-gsap-module',
    '@nuxtjs/fontawesome',
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    // https://go.nuxtjs.dev/pwa
    '@nuxtjs/pwa',
    '@nuxtjs/auth-next',
    'nuxt-vue-select'
  ],

  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    // Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
    baseURL: 'http://localhost:8000/api/',
    
  },

  // PWA module configuration: https://go.nuxtjs.dev/pwa
   pwa: {
    manifest: {
      lang: 'en',
    },
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
 build: {
    transpile: ["vee-validate/dist/rules"],
    vendor: ["vue-tables-2"]
  },
}

你尝试过删除 node_modules 文件夹,然后使用 yarn/pnpm 重新安装以检查一些错误吗?此外,你有 package.json 的备份吗?能否分享一下 nuxt.config.js 文件呢? - kissu
是的,我做了那个,当然可以,我会分享我的Nuxt配置文件。 - Romanric Akam
其余的呢? - kissu
2
这个回答解决了您的问题吗?错误信息“error:0308010C:digital envelope routines::unsupported” - segFault
不要删除 node_modules,这并不能解决问题。@kissu,你说的是哪个 rest 接口?那就是我的整个 nuxt.config 文件了。 - Romanric Akam
6个回答

45

在我的情况下,当我运行npm run build时,在Github Actions构建流水线中发生了这种情况。

我通过提供以下环境参数来解决了这个问题:

export NODE_OPTIONS=--openssl-legacy-provider

根据我的阅读,这个节点选项也可以在 package.json 中设置。
这似乎比降级 nodejs 到 v16 更容易。

这个解决方案最适合我在 Ubuntu 22.04 上使用 Node v18 LTS。 - Bekti Galan
1
只是确认一下,这个修复方案也适用于 macOS 13 Ventura 和 Node v20.3.1。 - undefined
确认一下,这个修复方法也适用于 macOS 13 Ventura 和 Node v20.3.1。 - rijam
在基于Ionic Angular的项目中遇到了相同的问题。这个解决方案对于我在MacOS Ventura上也起作用了。 - undefined

40

关于这个错误,在进行了大量研究后,我终于发现整个错误都是由nodejs升级到版本v18.12.1引起的,因此我建议所有最近升级到node v18.12.1并面临相同问题的人降级回node v16.0.0,如果你需要帮助,可以使用nvm

以下概述了一些步骤,包括一些资源链接

  1. 下载并安装nvm 请参考此处的说明
  1. 安装Nodejs v16.0.0 nvm install 16.0.0

  2. 卸载nodejs v18.12.1 nvm uninstall 18.12.1 或您自己的node版本

我真心希望这能像对我一样对其他人有所帮助,我知道框架错误会带来很多痛苦,请在评论中提出进一步的帮助要求。 谢谢。


1
对我来说起作用了。在Windows上,你只需像往常一样卸载Node.js 18,然后下载/安装16。 - Andrew
1
在执行此操作之前,请考虑此答案中的警告 - https://dev59.com/0VEG5IYBdhLWcg3wPXtF#73027407。 - Mark Gavagan
5
那不是解决方法。你需要升级使用过时SSL的过时库,而不是反过来。在我的情况下,这是一个旧版本的webpack。@MarkGavagan的评论中有描述正确解决方案的链接。 - vir us
1
将 Node 降级至 <17 对我起了作用;我使用的是 _react-scripts": "^4.0.0"_,但在看到 @MarkGavagan 的评论后,我执行了 npm audit fix --force 命令,它升级了我的 _react-scripts": "^5.0.1"_。之后,SSL 问题得到解决,并且现在可以使用 Node > 17 运行了。 - Marcelo Scofano Diniz
你不一定需要卸载v18,你可以只安装v16 nvm install 16,然后使用命令nvm use 16。使用16.0.0将阻止你升级到最新的次要版本和热修复版本。 - undefined

15

查看这里的解决方案后,我决定将node@16.0.0作为项目的开发依赖进行安装。

npm install node@16.0.0 --save-dev

然后在脚本中加入命令 "dev": "npm run serve"。

"scripts": {
    "dev": "npm run serve",
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
},

这将使得当你运行命令 "npm run dev" 时

npm run dev

它将使用您项目依赖项的节点来运行脚本。


1
这对我来说很有效,是一个很好的解决方案,比降级全局节点版本或者折腾 NVM 要简单得多。 - Daniel Davies

9

我花了很多时间解决这个问题。如果你正在使用 Fedora 并且出现了这个错误

尝试用标志运行你的项目:NODE_OPTIONS=--openssl-legacy-provider 例如:"dev": "NODE_OPTIONS=--openssl-legacy-provider next -p 4000"

如果它对你有帮助,那么你可以将其设置为 Node 环境

  • 在控制台中检查你的选项 echo $NODE_OPTIONS
  • 如果选项为空,请设置它 export NODE_OPTIONS=--openssl-legacy-provider

我使用的是 16.17.1 版本的 NodeJs,设置 NODE_OPTIONS 变量对我有帮助。

如果这不起作用,则尝试最后一步,在你的/etc/ssl/openssl.cnf文件中取消注释以下行。


在命令 'NODE_OPTIONS=--openssl-legacy-provider next -p 4000' 中,'next' 应该改为 'nuxt' 吗? - Farid
在命令“NODE_OPTIONS=--openssl-legacy-provider next -p 4000”中,'next' 应该改为 'nuxt',对吗? - undefined
完美,谢谢! - Aline Matos

0

你可以采用Romanric AKAM提供的答案,但如果你有多个项目需要不同的Node版本(在我的情况下,我有两个项目依赖于不同的版本)

所以在这种情况下,进入你遇到问题的项目目录并运行nvm install 16.0.0

注意:请先安装nvm


-1

我注意到有一个更新版本:Node-18.13.0。所以我尝试更新到这个最新版本,而不是回滚到以前的版本,但是它没有成功。

然后,我在这里检查了其他版本:

https://nodejs.org/dist/

安装版本 Node-v15.6.0 解决了我的问题。所以,暂时回退 Node 可能是我们最好的选择。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接