当前位置: 首页 > news >正文

npm内存溢出

项目过大运行项目内存溢出

报错代码

运行内存溢出 increase-memory-limit ‘“node --max-old-space-size=8192”’
不是内部或外部命令,也不是可运行的程序

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation
failed - JavaScript heap out of memory
‘cross-env‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件

解决方案

1.第一步:安装
使用 increase-memory-limit

npm install --save-dev increase-memory-limit
npm install --save-dev cross-env

安装完成插件,在package.json scripts中添加下面代码,并运行

"limit": "cross-env LIMIT=8192 increase-memory-limit",

2.第二步:替换 “%_prog%”
如果报错 “不是内部或外部命令” 在根目录下 新建与node-modules同级的文件,increase-memory-limit.js,把wfpath改成自己的项目地址即可,注意有两处地方需要调整

const fs = require('fs')
function replaceStr(filePath, sourceRegx, targetSrt) {  //文件路径、 需要修改的字符串、修改后的字符串fs.readFile(filePath, (err, data) => {if (err) console.log(err)else {let str = data.toString();str = str.replace(sourceRegx, targetSrt);fs.writeFile(filePath, str, (err) => {if (err) console.log(err);})}})
}
var wfPath = 'D:/mgsworker/newTran/node_modules/.bin'
fs.readdir(wfPath, (err, files) => {if (err) console.log(err);else {if (files.length != 0) {files.forEach((item) => {var wfPath = 'D:/mgsworker/newTran/node_modules/.bin';// 或者var wfPath =  path.resolve(__dirname, '../node_modules/.bin')if (item.split('.')[1] === 'cmd') {wfPath += `/${item}`;replaceStr(wfPath, /"%_prog%"/, '%_prog%')}})}}
})

在这里插入图片描述

3.第三步:运行替换:
文件根目录下执行命令:node increase-memory-limit.js 执行完可以删除脚本文件

4.第四步:正常运行和打包了

补充

当npm install 运行报错的时候 多半是源的问题;
因为访问https://registry.npmjs.org这个地址需要翻墙才能访问,所以在国内经常会出现连接超时等问题。为了解决这个问题,可以将npm的源设置为国内的镜像例如淘宝镜像。

npm config set registry https://registry.npmmirror.com
npm config get registry // 查看设置

npm 官方原始镜像网址是:https://registry.npmjs.org/
淘宝最新 NPM 镜像https://registry.npmmirror.com
阿里云 NPM 镜像: https://npm.aliyun.com
腾讯云 NPM 镜像:https://mirrors.cloud.tencent.com/npm/
华为云 NPM 镜像:https://mirrors.huaweicloud.com/repository/npm/
网易 NPM 镜像:https://mirrors.163.com/npm/
中科院大学开源镜像站:http://mirrors.ustc.edu.cn/
清华大学开源镜像站:https://mirrors.tuna.tsinghua.edu.cn/

http://www.lryc.cn/news/504507.html

相关文章:

  • 回归预测 | MATLAB实现CNN-BiGRU卷积神经网络结合双向门控循环单元多输入单输出回归预测
  • Android系统卡启动问题排查
  • STP(生成树协议)
  • 【前端面试】随机、结构赋值、博弈题
  • Volta——开箱即用的Node.js 版本管理工具
  • ubuntu 磁盘空间满,找不到占用文件的目录
  • 1. 机器学习基本知识(5)——练习题(参考答案)
  • spark-sql 备忘录
  • 基于softmax回归的多分类
  • bs4基本运用
  • MySQL 时区参数 time_zone 详解
  • Redis - 消息队列 Stream
  • Docker:国内加速源
  • Android Studio更改项目使用的JDK
  • ubuntu+ros新手笔记(四):gazebo无法加载
  • vue季度选择器(antd2.0 版本无此控件,单独写一个)
  • C/C++代码性能优化技巧的书籍及资料
  • 通俗易懂的 Nginx 反向代理 配置
  • docker设置容器自动启动
  • 蓝桥杯刷题——day1
  • Leetcode 面试150题 399.除法求值
  • 活动预告 |【Part2】Microsoft 安全在线技术公开课:安全性、合规性和身份基础知识
  • Unity游戏实战
  • SQL中的替换函数replace() 使用
  • Python面试常见问题及答案5
  • (css)element中el-select下拉框整体样式修改
  • 点击按钮打开dialog嵌套表格checked数据关闭dialog回显checked数据
  • 《拉依达的嵌入式\驱动面试宝典》—C/CPP基础篇(三)
  • 大模型呼出机器人有哪些优势和劣势?
  • Python鼠标轨迹算法(游戏防检测)