首页 > 解决方案 > 在 Windows 上使用 node.js 参数运行 grunt 任务

问题描述

运行 grunt babel 时遇到内存不足错误。在 mac 上通过增加 max-old-space-size 来解决。然而,我们的一些开发人员在 Windows 机器上,我还没有找到在 Windows 上执行此操作的方法。

什么是等价物:

node --max-old-space-size=10000 node_modules/.bin/grunt babel

在窗户上?

或者是否有一个通用命令适用于两者?

我的依赖:

"@babel/core": "^7.1.5",
"@babel/preset-env": "^7.1.5",
"grunt-babel": "^8.0.0",
"grunt": "^0.4.5",
"grunt-cli": "^1.3.1",
My babel config in gruntfile.js

我在 gruntfile 中的 babel 配置。

babel: {
  options: {
    compact: true,
    presets: ['@babel/preset-env'],
    sourceMap: true,
    inputSourceMap: sourceMapInJson)
  },
},

错误我在 Mac 上仍然在 Windows 上而不增加 max-old-space-size:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

我在带有 max-old-space-size 参数的 Windows 上遇到错误:

basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
         ^^^^^^^

SyntaxError: missing ) after argument list

标签: javascriptnode.jscmdterminalgruntjs

解决方案


Npm 包increase-memory-limit会有所帮助。

此模块在运行节点二进制文件时修复堆内存不足。

如其官方文档中所述

它将在您的 node_modules/.bin/* 文件中的所有节点调用中附加 --max-old-space-size=4096 。

希望这可以帮助!


推荐阅读