overriding package.json scripts - NPM

Is there a way to override package.json scripts? I can't change package.json because it will change it for everyone. i.e in our package we have

"script": {
    "dev": "yarn dev:build" 
}

I would like to add extra memory for this step as it keeps crashing on my computer. i.e

"scripts":{
    "dev": "\"node --max-old-space-size=9000 yarn dev:build\""
}

Solution 1:

You can't "override" package.json because the filename is hardcoded in NPM. You can create another script entry like:

"scripts":{
    "dev": "yarn dev:build" 
    "devlocal": "\"node --max-old-space-size=9000 yarn dev:build\""
}

Exclude package.json while committing to whatever SCM you are using, and the modified file would remain local to your machine only.

Having said that, what you are asking for (having another file to do the work of package.json), is not possible.

Solution 2:

It's not technically overriding a script, but you can execute what would be a script without actually adding it to package.json by calling npm exec in your terminal:

npm exec --max-old-space-size=9000 yarn dev:build