In the Node.js environment in IDEA, npm reports Error: 0308010C: digital envelope routines: unsupported

Note: If you need to dynamically and flexibly manage the version of Node.js, or switch the version of Node.js, if you don’t want to uninstall and reinstall, you can check my latest blog post: Install and configure nvm-windows to version Node.js and npm control . This article also duplicates some of the content of this article.

Node.js is a JavaScript runtime environment based on the Chrome V8 engine.
Node.js is an open source, cross-platform JavaScript runtime environment. Node.js uses an event-driven, non-blocking I/O model, making it lightweight and efficient. Node.js package manager npm is currently the most popular package manager for Node.js.

1. Install nodjs

Enter node -v and npm -v in CMD to display the error message in the figure below, which means that nodejs is not installed on your machine or global variables are not configured , which makes it unable to be used globally.
insert image description here

Download the Windows version of node-v18.16.0-x64.msi
official website https://nodejs.org/en/download
Chinese official website https://nodejs.org/zh-cn/download
insert image description here
insert image description here

2. Installation and configuration

2.1 Use the default installation

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

insert image description here

2.2 Configure environment variables

Configure user variable NODE_PATH and system variable Path

insert image description here
insert image description here

2.3 Detect path normal and Node.js and npm installation

#检测path正常
path 或者 echo %path%

#检测Node.js
node -v

#检测npm
npm -v

insert image description here

2.4 Configure npm

Create a new node_global & node_cache folder in the Node.js installation directory

#node_global是npm的全局模块的路径
#node_cache是npm使用时的cache即缓存的配置路径。

insert image description here
Configure the node_global and node_cache folders in CMD using the npm config set command in nmp config

npm config set prefix "D:\nodejs\node_global"
npm config set cache "D:\nodejs\node_cache"

insert image description here
Use the npm config set command in nmp config in CMD to configure mirror-regisry

#npm config set registry 设置镜像站
npm config set registry=http://registry.npm.taobao.org

insert image description here
Use the npm config get and npm config list commands to get configuration information:
insert image description here

After npm info vue needs to open CMD as an administrator , enter npm info vue

If you open CMD without an administrator and enter this command, an error will be reported :
insert image description here
Open CMD with an administrator and enter this command:
insert image description here
insert image description here

The cache file generated by the node_cache folder after using it for a period of time :
insert image description here

Extended information (skippable):

npm 是世界上最大的软件注册表。 来自各大洲的开源开发者使用 npm 来共享和借用包,许多组织也使用 npm 来管理私有开发。

npm 由三个不同的组件组成:
网站
命令行接口 (CLI)
注册表
使用 网站 发现包、设置配置文件和管理 npm 体验的其他方面。 例如,你可以设置 组织 来管理对公共或私有包的访问。

CLI 从终端运行,是大多数开发者与 npm 交互的方式。

注册表 是 JavaScript 软件及其周围元信息的大型公共数据库。

#使用 npm 去 . . .
为你的应用程序调整代码包,或按原样合并包。
下载你可以立即使用的独立工具。
使用 npx 运行包而不下载。
随时随地与任何 npm 用户共享代码。
将代码限制为特定的开发者。
创建组织以协调包维护、编码和开发者。
通过使用组织形成虚拟团队。
管理多个版本的代码和代码依赖项。
更新底层代码时轻松更新应用程序。
发现解决同一个难题的多种方法。
寻找正在处理类似问题和项目的其他开发者。


Extension link:
1. About npm
2. npm CLI
------- CLI command
------- configure npm
-------- use npm

3. In the Node.js environment in IDEA, npm reports an error error: 0308010C

3.1 Obtain administrator privileges in the terminal of idea

insert image description here

Here are two npm CLI commands:

#此命令安装一个包和它所依赖的任何包。 如果包有一个包锁,或者一个 npm 收缩封装文件,或者一个纱线锁文件,依赖项的安装将由
#它驱动,遵循以下优先顺序:npm-shrinkwrap.json、package-lock.json、yarn.lock
#npm  install

#运行dev模块(运行任意包脚本、这会从包的 "scripts" 对象运行任意命令。)
#npm run dev

Details:
npm-install
npm-run-script

3.2 npm install

cd into the front-end folder Ruoyi-ui , execute npm install :
insert image description here
insert image description here

3.3 npm run dev

insert image description here
Error:0308010C:digital envelope routines::unsupported

This problem is due to the version of Node.js. The Node.js installed here is the latest long-term maintenance version: 18.16.0 (includes npm 9.5.1)

There are two solutions:

#1、方法一
重新安装低版本的node.js

#2、方法二
在package.json文件中进行配置【此种方法较简单】

The "scripts" property of the package.json file supports many built-in scripts and their preset lifecycle events as well as arbitrary scripts. These can all be executed by running npm run-script or npm run for short. Pre and post commands with matching names will also be run for these (eg premyscript, myscript, postmyscript). Scripts from dependencies can be run using npm explore - npm run.

Open the project directory, click on the npm-related package.json file
insert image description here
package.json to configure SET NODE_OPTIONS
insert image description here
After the configuration is complete, execute npm run dev again , and the compilation is completed successfully. ( The Proxy error below is because the backend service is not enabled.)
insert image description here

4. References

Latest LTS Version: 18.16.0 (includes npm 9.5.1)
Latest long-term maintenance version: 18.16.0 (includes npm 9.5.1)
(the most detailed on the whole network!!) npm: Cannot recognize "npm" item as cmdlet, function , the name of a script file or
an executable
program
scripts)
package.json (npm's package.json handling details)
using the npm
developers guide (using npm to develop (and possibly publish/deploy) your project)
scripts-scripts (how npm handles the "scripts" field)

Vue error error: 0308010C: digital envelope routines::unsupported
caused by the new version of nodejs: digital envelope routines::unsupported
caused by the new version of nodejs: digital envelope routines::unsupported

Vue-CLI installation, use and environment configuration (super detailed)
npm global installation failed, reporting -4048 error (npm ERR code EPERMnpm ERR syscall mkdirnpm ERR path C:\…)
npm install -g @vue/cli installing vue scaffolding error (Generally, it can be solved)
Problems encountered when npm starts the project

Guess you like

Origin blog.csdn.net/qyfx123456/article/details/131173811