django-npm
raw JSON → 1.0.1 verified Fri May 01 auth: no python
A Django staticfiles finder that uses npm. Integrates Node.js packages into Django's static file system by scanning node_modules directories. Current version: 1.0.1. Low maintenance, occasional updates for Django compatibility.
pip install django-npm Common errors
error ModuleNotFoundError: No module named 'django_npm' ↓
cause Missing 'django_npm' in INSTALLED_APPS or incorrect import path.
fix
Add 'django_npm' to INSTALLED_APPS and ensure you import from 'django_npm.finders'.
error ImproperlyConfigured: The NPM_STATIC_FILES_PREFIX setting is required. ↓
cause The setting NPM_STATIC_FILES_PREFIX is required in Django settings when using NpmFinder. It defines the subdirectory within STATIC_ROOT for npm files.
fix
Add NPM_STATIC_FILES_PREFIX = 'npm' to your settings (or any prefix of your choice).
Warnings
gotcha NpmFinder must come after the default finders; otherwise, default finders may override npm static files, leading to missing assets. ↓
fix Place NpmFinder last in the STATICFILES_FINDERS list.
gotcha django-npm does not automatically install npm packages or run 'npm install'. You must ensure node_modules is populated in your project's static root or a discoverable location. ↓
fix Run 'npm install' in your project directory before 'collectstatic'.
deprecated Python 3.8 and lower are no longer supported. Requires Python >= 3.9. ↓
fix Upgrade Python to 3.9+.
Imports
- NpmFinder
from django_npm.finders import NpmFinder
Quickstart
INSTALLED_APPS = [
'django_npm',
# ...
]
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django_npm.finders.NpmFinder',
]