sandbox-npm-install
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSandbox npm Install
沙箱环境npm安装
When to Use This Skill
何时使用此方法
Use this skill whenever:
- You need to install npm packages for the first time in a new sandbox session
- or
package.jsonhas changed and you need to reinstallpackage-lock.json - You encounter native binary crashes with errors like ,
SIGILL,SIGSEGV, ormmapunaligned sysNoHugePageOS - The directory is missing or corrupted
node_modules
当你遇到以下情况时使用:
- 需要在新的沙箱会话中首次安装npm包
- 或
package.json已更改,需要重新安装package-lock.json - 遇到原生二进制文件崩溃,错误如、
SIGILL、SIGSEGV或mmapunaligned sysNoHugePageOS - 目录缺失或损坏
node_modules
Prerequisites
前置条件
- A Docker sandbox environment with a virtiofs-mounted workspace
- Node.js and npm available in the container
- A file in the target workspace
package.json
- 带有通过virtiofs挂载工作区的Docker沙箱环境
- 容器内已安装Node.js和npm
- 目标工作区中存在文件
package.json
Background
背景
Docker sandbox workspaces are typically mounted via virtiofs (file sync between the host and Linux VM). Native Go and Rust binaries (esbuild, lightningcss, rollup, etc.) crash with mmap alignment failures when executed from virtiofs on aarch64. The fix is to install on the container's local ext4 filesystem and symlink back into the workspace.
Docker沙箱工作区通常通过virtiofs(主机与Linux虚拟机之间的文件同步)挂载。原生Go和Rust二进制文件(如esbuild、lightningcss、rollup等)在aarch64架构的virtiofs上执行时,会因mmap对齐失败而崩溃。解决方法是将包安装在容器的本地ext4文件系统中,再创建符号链接回工作区。
Step-by-Step Installation
分步安装步骤
Run the bundled install script from the workspace root:
bash
bash scripts/install.sh从工作区根目录运行捆绑的安装脚本:
bash
bash scripts/install.shCommon Options
常用选项
| Option | Description |
|---|---|
| Path to directory containing |
| Also install Playwright Chromium browser for E2E testing |
| 选项 | 描述 |
|---|---|
| 包含 |
| 同时安装Playwright Chromium浏览器以用于端到端测试 |
What the Script Does
脚本执行的操作
- Copies ,
package.json, andpackage-lock.json(if present) to a local ext4 directory.npmrc - Runs (or
npm ciif no lockfile) on the local filesystemnpm install - Symlinks back into the workspace
node_modules - Verifies known native binaries (esbuild, rollup, lightningcss, vite) if present
- Optionally installs Playwright browsers and system dependencies (uses when available)
sudo
If verification fails, run the script again — crashes can be intermittent during initial setup.
- 将、
package.json和package-lock.json(如果存在)复制到本地ext4目录.npmrc - 在本地文件系统上运行(如果没有锁文件则运行
npm ci)npm install - 将符号链接回工作区
node_modules - 如果存在已知原生二进制文件(esbuild、rollup、lightningcss、vite),则进行验证
- 可选安装Playwright浏览器和系统依赖项(如果可用则使用)
sudo
如果验证失败,请重新运行脚本——初始设置期间崩溃可能是间歇性的。
Post-Install Verification
安装后验证
After the script completes, verify your toolchain works. For example:
bash
npm test # Run project tests
npm run build # Build the project
npm run dev # Start dev server脚本完成后,验证你的工具链是否正常工作。例如:
bash
npm test # 运行项目测试
npm run build # 构建项目
npm run dev # 启动开发服务器Important Notes
重要注意事项
- The local install directory (e.g., ) is container-local and is NOT synced back to the host
/home/agent/project-deps - The symlink appears as a broken link on the host — this is harmless since
node_modulesis typically gitignorednode_modules - Running or
npm cion the host naturally replaces the symlink with a real directorynpm install - After any or
package.jsonchange, re-run the install scriptpackage-lock.json - Do NOT run or
npm cidirectly in the mounted workspace — native binaries will crashnpm install
- 本地安装目录(例如)是容器本地的,不会同步回主机
/home/agent/project-deps - 在主机上符号链接显示为损坏的链接——这是无害的,因为
node_modules通常会被git忽略node_modules - 在主机上运行或
npm ci会自然地将符号链接替换为真实目录npm install - 任何或
package.json更改后,重新运行安装脚本package-lock.json - 不要在挂载的工作区中直接运行或
npm ci——原生二进制文件会崩溃npm install
Troubleshooting
故障排除
| Problem | Solution |
|---|---|
| Re-run the install script; ensure you're not running |
| Check that the symlink exists: |
| Permission errors during install | Ensure the local deps directory is writable by the current user |
| Verification fails intermittently | Run the script again — native binary crashes can be non-deterministic on first load |
| 问题 | 解决方案 |
|---|---|
运行开发服务器时出现 | 重新运行安装脚本;确保不要在工作区中直接运行 |
安装后找不到 | 检查符号链接是否存在: |
| 安装期间出现权限错误 | 确保本地依赖目录对当前用户可写 |
| 验证间歇性失败 | 重新运行脚本——原生二进制文件在首次加载时的崩溃可能是非确定性的 |
Vite Compatibility
Vite兼容性
If your project uses Vite, you may need to allow the symlinked path in . Add the symlink target's parent directory (e.g., ) to your Vite config so that Vite can serve files through the symlink.
server.fs.allow/home/agent/project-deps/如果你的项目使用Vite,你可能需要在中允许符号链接路径。将符号链接目标的父目录(例如)添加到你的Vite配置中,以便Vite可以通过符号链接提供文件。
server.fs.allow/home/agent/project-deps/