记录解决Electron开发使用node 32位是内存移除导致无法热更新问题

770 阅读1分钟

Electron win32 内存溢出

vue-cli electron node32 内存溢出

<--- Last few GCs --->

[22168:0431A9C8]   489887 ms: Mark-sweep (reduce) 654.4 (765.3) -> 654.4 (727.8) MB, 222.1 / 0.0 ms  (average mu = 0.214, current mu = 0.002) last resort GC in old space requested
[22168:0431A9C8]   490124 ms: Mark-sweep (reduce) 654.4 (723.8) -> 654.4 (705.5) MB, 236.8 / 0.1 ms  (average mu = 0.117, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! Matrx@1.0.24 dev: `vue-cli-service electron:serve`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the Matrx@1.0.24 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
# 切换到目录 `node_modules/.bin/`
cd node_modules/.bin/
# webpack.ps1
# webpack.cmd
# webpack-dev-server.ps1
# webpack-dev-server.cmd
# vue-cli-service.cmd
# vue-cli-service.ps1

webpack.cmd 修改前

@ECHO off
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

"%_prog%"  "%dp0%\..\webpack\bin\webpack.js" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b

webpack.cmd 修改后

@ECHO off
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe --max-old-space-size=10240"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

"%_prog%"  "%dp0%\..\webpack\bin\webpack.js" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b

webpack.ps1 修改前

#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent

$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
  # Fix case when both the Windows and Linux builds of Node
  # are installed in the same directory
  $exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
  & "$basedir/node$exe"  "$basedir/../webpack/bin/webpack.js" $args
  $ret=$LASTEXITCODE
} else {
  & "node$exe"  "$basedir/../webpack/bin/webpack.js" $args
  $ret=$LASTEXITCODE
}
exit $ret

webpack.ps1 修改后

#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent

$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
  # Fix case when both the Windows and Linux builds of Node
  # are installed in the same directory
  $exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
  & "$basedir/node$exe" --max-old-space-size=10240  "$basedir/../webpack/bin/webpack.js" $args
  $ret=$LASTEXITCODE
} else {
  & "node$exe" --max-old-space-size=10240  "$basedir/../webpack/bin/webpack.js" $args
  $ret=$LASTEXITCODE
}
exit $ret

其他的文件相同的修改就行