Tag Archives: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed

[Solved] NPM Error: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed

Problem Description:

Resolve NPM exception: fatal error: ineffective mark compacts near heap limit allocation failed

Solution:

1. Delete the. Npmrc file under C:\users {account}\.
2. Clean it directly with the command. Enter
NPM cache clean – force
3 on the CMD console, or clean it directly with the command. Enter cnpm install – G increase memory limit on the CMD console, and then increase memory limit

when running the Vue project, no error will be reported

[Solved] NPM Error: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed

This error is reported when NPM run build is executed to package Vue project, because the maximum value of node file set is not enough and the file after project packaging is too large.

Solution: install increase memory limit globally

Command line CMD, DOS window running: cnpm install – G increase memory limit,

Enter the project folder and run: increase memory limit

If NPM run build reports an error ‘node — Max old space size = 10240’ after executing increase memory limit after entering the project file, it is neither an internal or external command nor a runnable program ‘

You can create the following JS file contents in the project root directory, execute the file with node, and then run NPM run build to package successfully. This is to replace the public function of the string in the file corresponding to the. Bin file under the node_mosules file.

// Execute this script via node the first time you run the project
const fs = require('fs')
const path = require('path')
const wfPath =  path.resolve(__dirname, './node_modules/.bin')

fs.readdir(wfPath, (err, files)=>{
   if (err) {
    console.log(err);
   } else {
      if(files.length != 0 ) {
        files.forEach((item)=>{
           if(item.split('.')[1] === 'cmd') {
              replaceStr(`${wfPath}/${item}`, /"%_prog%"/, '%_prog%')
           }
        })
     }
   }
 })

// Parameters: [file path, string to be modified, modified string] (public function to replace the string in the corresponding file)
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)=> { console.log(err) })
     }
  })
}