[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) })
     }
  })
}

Read More: