Node Vue 项目开发常见问题解决

记录平时Node Vue 项目开发中遇到问题及解决方案,不喜勿喷

目录

[一、Nodejs 安装](#一、Nodejs 安装)

[二、NPM 设置镜像代理](#二、NPM 设置镜像代理)

[三、解决node升级到18 的问题](#三、解决node升级到18 的问题)

[四、resolutions 解决包冲突问题](#四、resolutions 解决包冲突问题)

五、core-js安装后,运行报错


一、Nodejs 安装

Nodejs 下载

或是使用NVM管理nodejs 版本

NVM下载

二、NPM 设置镜像代理

复制代码
npm config set registry https://registry.npmmirror.com   
npm config set registry cls
npm config get registry

淘宝镜像仓库(国内):https://registry.npmmirror.com

华为镜像仓库(国内):https://repo.huaweicloud.com/repository/npm/

清华镜像仓库 :https://mirrors.tuna.tsinghua.edu.cn/

三、解决node升级到18 的问题

1、增加一项 NODE_OPTIONS=--openssl-legacy-provider

复制代码
// 运行配置
NODE_OPTIONS=--openssl-legacy-provider
或  
SET NODE_OPTIONS=--openssl-legacy-provider
 如:"dev": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve --open --copy",
  1. 使用 sass 代替 node-sass,这里需要注意版本 sass 与 sass-loader 版本

    npm unintall node-sass
    npm install sass -D

四、resolutions 解决包冲突问题

问题:yarn insntall 报错,显示 @achrinza/node-ipc@9.2.2 不支持现在的node版本

复制代码
error @achrinza/node-ipc@9.2.2: The engine "node" is incompatible with this module. Expected version "8 || 10 || 12 || 14 || 16 || 17". Got "18.10.0"
error Found incompatible module.

resolutions 是一个用于解决依赖项冲突的 npm 特殊字段。在某些情况下,项目依赖项可能需要不同的版本,而这些版本之间可能存在冲突。

复制代码
## package.json中 添加 @achrinza/node-ipc
{
  "name": "my-project",
  "version": "1.1.0",
  "scripts": {
    ....
  },
  "dependencies": {
   ....
  },
  "devDependencies": {
      ....
  },
  

"engines": {},
  "browserslist": [
    "> 1%",
    "last 2 versions"
  ],
  
    //添加  @achrinza/node-ipc
  "resolutions": {
    "@achrinza/node-ipc": "9.2.9"
  }
}

五、core-js安装后,运行报错

复制代码
$ vue-cli-service serve
 INFO  Starting development server...
98% after emitting CopyPlugin

 ERROR  Failed to compile with 162 errors                               15:07:00

These dependencies were not found:

* core-js/modules/es.iterator.constructor.js in ./node_modules/@babel/runtime/helpers/objectSpread2.js, ./node_modules/quill/blots/block.js and 54 others
* core-js/modules/es.iterator.every.js in ./node_modules/quill/modules/keyboard.js, ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Tinymce/components/EditorImage.vue?vue&type=script&lang=js and 2 others
* core-js/modules/es.iterator.filter.js in ./node_modules/@babel/runtime/helpers/objectSpread2.js, ./node_modules/quill/blots/scroll.js and 12 others
* core-js/modules/es.iterator.find.js in ./node_modules/quill/blots/scroll.js, ./node_modules/quill/core/composition.js and 5 others
* core-js/modules/es.iterator.for-each.js in ./node_modules/@babel/runtime/helpers/objectSpread2.js, ./node_modules/quill/blots/block.js and 24 others
* core-js/modules/es.iterator.map.js in ./node_modules/quill/blots/block.js, ./node_modules/quill/core/editor.js and 36 others
* core-js/modules/es.iterator.reduce.js in ./node_modules/quill/blots/block.js, ./node_modules/quill/core/quill.js and 4 others
* core-js/modules/es.iterator.some.js in ./node_modules/quill/blots/cursor.js, ./node_modules/quill/core/selection.js and 9 others

To install them, you can run: npm install --save core-js/modules/es.iterator.constructor.js core-js/modules/es.iterator.every.js core-js/modules/es.iterator.filter.js core-js/modules/es.iterator.find.js core-js/modules/es.iterator.for-each.js core-js/modules/es.iterator.map.js core-js/modules/es.iterator.reduce.js core-js/modules/es.iterator.some.js

1、首先检查 package.json 中是有 core-js 以及版本 如: "core-js": "3.37.1"

2 、检查node-modules 目录中是否存在 core-js 及版本

如果版本不一样,需要删除重新安装

复制代码
npm uninstall core-js  或 yarn remove core-js
删除node-modules 中 core-js 文件夹
或按下步骤执行:
1、先删除 node_modules 依赖
    npm rm -rf node_modules 
  或 
   yarn remove node_modules
2、首先安装 报错的插件
    npm install --save core-js
    或
    yarn add --save core-js
3、最后再 npm install 或者 yarn install
     npm install 
     或
     yarn install
4、最后 npm run dev 运行启动
     npm run dev
     或
     yarn dev
相关推荐
GreenTea1 小时前
GrokBot 核心成员 Lauren Tan:每月交付 2000 个 PR 的人,是怎么用 AI 的
前端·后端·架构
mCell2 小时前
用 Knip 清理 AI Coding 留下的冗余代码
前端·ai编程·前端工程化
Hvitur3 小时前
Linux安装Git【离线安装】
git
dy17173 小时前
vue2树节点刷新后定位到上一节点展开
vue.js
笃行3503 小时前
使用Rokid AIUI做了一个童年推箱子游戏
前端
excel4 小时前
前端加密的作用与使用场景
前端
计算机魔术师5 小时前
纽约时报版权诉讼披露:微软高管内部称训练 AI 是人类历史上最大规模劳动窃取
前端
去伪存真6 小时前
大模型的参数量为什么那么大?
前端·人工智能
IT_陈寒6 小时前
Java空指针这次真把我坑惨了
前端·人工智能·后端
高级程序源7 小时前
django大学生创新创业项目管理系统94923-计算机课程设计、毕业设计
javascript·vue.js·spring boot·后端·python·django·课程设计