To use npm packages in Lovable, prompt the AI to install and use the package by name: 'Use the react-pdf package to add a PDF viewer to the documents page.' Lovable handles installation and integration automatically. If a package causes build errors, check that it is compatible with browser environments (not Node.js-only). For private packages, add your npm token in Workspace Settings, then Build Secrets. Version conflicts can be resolved by asking Lovable to pin a specific version.
Why external libraries sometimes break in Lovable projects
Lovable projects use Vite as the build system, which bundles npm packages for the browser. Most popular React-compatible packages work out of the box when you ask Lovable to install them. However, some packages are designed for Node.js server environments and use APIs that do not exist in browsers — like 'fs' (file system), 'path', 'crypto', or raw TCP sockets. When Lovable installs a Node.js-only package, the build may succeed but the app crashes at runtime with errors like 'Module not found: fs' or 'process is not defined.' Other times, a package works initially but conflicts with an existing dependency version, causing subtle bugs or build failures. Lovable does not have a terminal, so you cannot run npm install manually. Instead, you tell the AI which package to use and it handles the installation through the prompt. This works well for most packages, but you need to know how to troubleshoot when things go wrong — especially with packages that require post-install configuration, peer dependencies, or special Vite plugins.
- Package requires Node.js APIs not available in browsers — fs, path, child_process, net
- Version conflict with existing dependencies — the new package needs a different version of React or another shared dependency
- Missing peer dependencies — the package requires additional packages that were not installed automatically
- Package requires Vite plugin configuration — some packages need entries in vite.config.ts to work with the bundler
- Private package without authentication — npm registry rejects the install because no auth token is configured
Error messages you might see
Module not found: Error: Can't resolve 'fs'The package you installed uses Node.js file system APIs that do not exist in the browser. Look for a browser-compatible alternative, or use the package only inside a Supabase Edge Function where Node-like APIs are available.
Uncaught ReferenceError: process is not definedThe package references 'process.env' or other Node.js globals. In Vite projects, you can add a define entry in vite.config.ts to polyfill process.env, or find a browser-native alternative.
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@private/packageThe package is private or scoped to an organization. You need to add your npm authentication token in Workspace Settings, then Build Secrets for Lovable to access it during installation.
ERESOLVE unable to resolve dependency tree: peer dep conflictThe package you are installing requires a different version of a dependency that is already in your project. Ask Lovable to install a specific version that is compatible, or use the --legacy-peer-deps flag.
Before you start
- A Lovable project open in the editor
- The name of the npm package you want to use (check npmjs.com for browser compatibility)
- For private packages: your npm authentication token from your npm account or organization
How to fix it
Prompt Lovable to install and use the package
Lovable handles npm installation through the prompt — there is no terminal to run npm install manually
Prompt Lovable to install and use the package
Lovable handles npm installation through the prompt — there is no terminal to run npm install manually
In Agent Mode, write a prompt that names the specific package and describes how you want to use it. Be specific about the component or feature. For example: 'Use the @hello-pangea/dnd npm package to add drag-and-drop functionality to my Kanban board on the projects page.' Lovable will install the package, import it in the relevant file, and integrate it into your component. Avoid vague prompts like 'add a charting library' — name the exact package.
// Vague prompt — Lovable might pick the wrong package// "Add charts to my dashboard"// Specific prompt — Lovable installs exactly what you want// "Use the recharts npm package to add a line chart to// @src/pages/Dashboard.tsx showing monthly revenue data.// The chart should use the ResponsiveContainer component// and display data from the revenue_data state variable."Expected result: Lovable installs the package, adds the import, and integrates it into your component. The feature appears in the preview.
Check if the package is browser-compatible
Node.js-only packages crash in the browser with missing module errors
Check if the package is browser-compatible
Node.js-only packages crash in the browser with missing module errors
Before asking Lovable to install a package, check its npm page (npmjs.com) for browser compatibility. Look for keywords like 'browser', 'frontend', or 'client-side' in the description. Check if the package has a 'browser' or 'module' field in its package.json — this indicates browser support. If the package is Node.js-only, look for a browser alternative. For example, use 'uuid' (browser-compatible) instead of 'crypto.randomUUID()' for older browsers, or 'axios' instead of Node's 'http' module.
// Node.js-only package — will crash in browserimport { readFileSync } from "fs";import { join } from "path";const config = JSON.parse(readFileSync(join(__dirname, "config.json"), "utf-8"));// Browser-compatible alternative — fetch config from API or use static importconst config = { apiUrl: import.meta.env.VITE_API_URL || "https://api.example.com", maxRetries: 3,};// Or fetch from a Supabase Edge Function if config is dynamicimport { supabase } from "@/integrations/supabase/client";const { data: config } = await supabase.functions.invoke("get-config");Expected result: The package works in the browser without 'Module not found' or 'process is not defined' errors.
Fix version conflicts by pinning a specific version
Dependency tree conflicts prevent installation — pinning a compatible version resolves the issue
Fix version conflicts by pinning a specific version
Dependency tree conflicts prevent installation — pinning a compatible version resolves the issue
If you see an ERESOLVE error about peer dependency conflicts, ask Lovable to install a specific older version of the package that is compatible with your existing dependencies. Check the package's npm page for version history and find a version that matches your React version. Prompt: 'Install react-beautiful-dnd version 13.1.1 instead of the latest version — the latest requires React 18 but my project uses React 17.'
// Lovable tries to install the latest version which conflicts// Error: ERESOLVE unable to resolve dependency tree// peer dep requires react@^18.0.0 but found react@17.0.2// Ask Lovable to install a compatible version// "Install @hello-pangea/dnd version 16.5.0 which supports React 17.// This is a maintained fork of react-beautiful-dnd that works// with the React version in my Lovable project."// Or in the prompt:// "Update my project to use the latest React version first,// then install the chart library"Expected result: The package installs without version conflicts. The dependency tree resolves cleanly.
Configure private package authentication
Private npm packages require authentication tokens to download during the build process
Configure private package authentication
Private npm packages require authentication tokens to download during the build process
If you are using packages from a private npm registry or a scoped organization package, you need to provide an authentication token. Go to Workspace Settings (click your workspace name in the top-left), then Build Secrets. Add a secret named NPM_TOKEN with your npm authentication token (find this by running 'npm token create' in your local terminal, or get it from your npm account settings). Lovable uses this token during the build process to authenticate with the npm registry. If your organization uses a proxy like a custom Artifactory, RapidDev's engineers can help configure the authentication correctly.
// Build fails because private package requires authentication// npm ERR! 404 Not Found - @your-org/design-system// 1. Go to Workspace Settings → Build Secrets// 2. Add: NPM_TOKEN = your-npm-auth-token//// Lovable automatically creates a .npmrc during build:// //registry.npmjs.org/:_authToken=${NPM_TOKEN}//// Now private packages install successfully during buildExpected result: Private packages install successfully during the build. The NPM_TOKEN is used for authentication without being exposed in code.
Complete code example
1import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from "recharts";2import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";34// Sample data — replace with your actual data source5const revenueData = [6 { month: "Jan", revenue: 4000 },7 { month: "Feb", revenue: 3000 },8 { month: "Mar", revenue: 5000 },9 { month: "Apr", revenue: 4500 },10 { month: "May", revenue: 6000 },11 { month: "Jun", revenue: 5500 },12];1314export default function ChartDashboard() {15 return (16 <Card>17 <CardHeader>18 <CardTitle>Monthly Revenue</CardTitle>19 </CardHeader>20 <CardContent>21 {/* ResponsiveContainer makes the chart adapt to parent width */}22 <ResponsiveContainer width="100%" height={300}>23 <LineChart data={revenueData}>24 <CartesianGrid strokeDasharray="3 3" />25 <XAxis dataKey="month" />26 <YAxis />27 <Tooltip />28 <Line29 type="monotone"30 dataKey="revenue"31 stroke="#8884d8"32 strokeWidth={2}33 // Smooth animation when data changes34 animationDuration={300}35 />36 </LineChart>37 </ResponsiveContainer>38 </CardContent>39 </Card>40 );41}Best practices to prevent this
- Always name the exact npm package in your prompt — do not say 'add a chart library,' say 'use the recharts npm package'
- Check the package's npm page for browser compatibility before requesting installation — look for 'browser' or 'module' field
- Use well-maintained, popular packages — they are more likely to work with Vite and have good browser support
- Pin specific versions when you encounter peer dependency conflicts — ask Lovable to install a compatible version
- For private packages, add your NPM_TOKEN in Workspace Settings, then Build Secrets before requesting the install
- If a package needs a Vite plugin, mention it in your prompt: 'Install the package and add its Vite plugin to vite.config.ts'
- Test the package in the preview immediately after installation — do not add more features on top before verifying it works
- Keep a list of packages your project uses in AGENTS.md so the AI knows what is already installed
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I have a Lovable (lovable.dev) project using Vite + React + TypeScript + Tailwind CSS. I want to add an npm package but I am getting errors. Package I want to use: [package name] Error I see: [paste exact error message] Here is my current vite.config.ts: [Paste your vite.config.ts here] Here is my package.json dependencies section: [Paste your dependencies here] Please: 1. Check if this package is browser-compatible 2. Identify any version conflicts with my existing dependencies 3. Suggest a compatible version or alternative package 4. Show any vite.config.ts changes needed for the package to work 5. Provide the correct import statement and basic usage example
Install the [package-name] npm package and use it in @src/components/[ComponentName].tsx. If the latest version causes dependency conflicts, use version [x.x.x] which is compatible with React 18. After installing, import the component and integrate it into my existing layout. If the package needs any Vite plugin configuration, update vite.config.ts as well. Show me the working result in the preview.
Frequently asked questions
How do I install npm packages in Lovable?
Prompt Lovable's AI with the exact package name and how you want to use it. For example: 'Use the date-fns npm package to format dates in the activity feed.' Lovable handles the npm installation and integration automatically. There is no terminal to run npm install manually.
Why does my npm package cause 'Module not found: fs' in Lovable?
The package uses Node.js file system APIs that do not exist in browsers. Lovable projects run entirely in the browser, so only browser-compatible packages work in frontend code. Look for a browser alternative, or move the code that uses this package into a Supabase Edge Function where server-side APIs are available.
Can I use private npm packages in Lovable?
Yes. Go to Workspace Settings, then Build Secrets, and add a secret named NPM_TOKEN with your npm authentication token. Lovable uses this token during the build process to authenticate with the npm registry and download your private packages.
How do I fix dependency version conflicts in Lovable?
Ask Lovable to install a specific version that is compatible with your existing dependencies. Check the package's npm page for version history. For example: 'Install chart.js version 3.9.1 instead of version 4, because my project uses an older adapter.'
What npm packages work best with Lovable?
Packages that are browser-compatible and work with React and Vite. Popular choices include: recharts (charts), @hello-pangea/dnd (drag and drop), date-fns (date formatting), zod (validation), react-hook-form (forms), and framer-motion (animations). All of these are well-tested with Lovable's stack.
Does Lovable install packages automatically or do I need to specify them?
You need to specify the package name in your prompt. Lovable does not automatically choose packages — it installs what you request. Being specific about the package name and version ensures you get exactly the library you want.
What if I can't get a package working in Lovable?
If a package requires complex Vite configuration, custom polyfills, or has deep dependency conflicts, RapidDev's engineers can help. They have integrated hundreds of npm packages into Lovable projects and know which packages need special handling.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your issue.
Book a free consultation