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

在Render部署Django应用执行tailwind build遇npm报错求助

解决Render部署Django+Tailwind时的rimraf未找到错误

问题详情

在Render平台部署Django应用(本地为Windows系统,项目使用Tailwind CSS),执行命令python manage.py tailwind build时触发以下npm错误:

sh: 1: rimraf: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! theme@3.4.0 build:clean: `rimraf ../static/css/dist`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the theme@3.4.0 build:clean script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

当前配置:

  • requirements.txt中包含:nodejs==0.1.1、npm==0.1.1
  • settings.py设置:NPM_BIN_PATH = "/usr/bin/npm"
  • build.sh内容:
set -o errexit

pip install -r requirements.txt
python manage.py collectstatic --no-input
python manage.py migrate
python manage.py tailwind build

if [[ $CREATE_SUPERUSER ]];
then
  python manage.py createsuperuser --no-input
fi

解决方案

  • 移除pip的Node.js/npm依赖:requirements.txt里的nodejs和npm是Python模拟包,并非真正的Node.js环境。Render平台默认自带Node.js/npm,无需通过pip安装,直接删除这两行。
  • 安装Tailwind项目依赖:在执行tailwind build前,先进入Tailwind主题目录(通常是项目中的theme文件夹)执行npm install,确保rimraf等依赖被正确安装。修改build.sh如下:
set -o errexit

pip install -r requirements.txt
# 进入Tailwind主题目录安装npm依赖
cd theme
npm install
cd ..
python manage.py collectstatic --no-input
python manage.py migrate
python manage.py tailwind build

if [[ $CREATE_SUPERUSER ]];
then
  python manage.py createsuperuser --no-input
fi
  • 确认NPM_BIN_PATH路径:在Render虚拟机中执行which npm可获取正确的npm路径,通常为/usr/local/bin/npm,将settings.py中的NPM_BIN_PATH修改为该路径。
  • 验证Node.js版本:可在build.sh开头添加node --version和npm --version命令,确保Node.js版本≥16(Tailwind CSS的最低要求)。

内容的提问来源于stack exchange,提问作者Raúl Gallardo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 05:35:12