You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过npm link命令设置--max-old-space-size参数?

Great question! The short answer is: npm link itself doesn't support passing the --max-old-space-size parameter directly—since npm link is mainly for creating symlinks between local packages and your global npm setup. But there are several solid workarounds to make sure your linked package runs with the memory limit you want:

1. Wrap your CLI in a package.json script

If your package has a CLI entry point, you can define a script in your package.json that includes the memory parameter. After linking, users can run this script to launch your tool with the configured limit.

Example:

{
  "name": "your-local-package",
  "bin": "./src/cli.js",
  "scripts": {
    "start": "node --max-old-space-size=4096 ./src/cli.js"
  }
}

After running npm link, users just need to execute npm start in their project to use your CLI with the specified memory allocation.

2. Add the parameter to your CLI's shebang line (Unix-like systems only)

For Linux or macOS, modify the shebang at the top of your CLI entry file to include the memory parameter. This will automatically apply the setting whenever someone runs your CLI command directly.

Example in ./src/cli.js:

#!/usr/bin/env node --max-old-space-size=4096

// Rest of your CLI code goes here...

⚠️ Heads up: This won't work on Windows, since Windows doesn't recognize shebang lines.

3. Set the NODE_OPTIONS environment variable

You can configure an environment variable that tells Node.js to use your desired memory limit for all processes launched via npm. This works globally for the current session.

  • Linux/macOS:
    export NODE_OPTIONS="--max-old-space-size=4096"
    
  • Windows Command Prompt:
    set NODE_OPTIONS="--max-old-space-size=4096"
    
  • Windows PowerShell:
    $env:NODE_OPTIONS="--max-old-space-size=4096"
    

Note: This affects all Node.js processes in the session, not just your linked package.

4. Manually pass the parameter when running the CLI

For one-off runs, users can call Node.js directly with the memory parameter and point to the linked CLI executable:

node --max-old-space-size=4096 $(which your-cli-command)

This works across all operating systems but requires users to remember the command structure.


内容的提问来源于stack exchange,提问作者Sai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:46:52