Last modified: Jun 24, 2026

Fix Stripe Module Not Found in Node

If you are building a payment system in Node.js, you might see this error: Cannot find module 'stripe'. This stops your app from running. It is a common problem for beginners. The good news is that it is easy to fix. This guide will show you why it happens and how to solve it.

First, do not panic. This error means Node.js cannot locate the Stripe package in your project. It usually happens because the package is not installed or is missing from the right folder. Let us look at the main causes and solutions.

Why Does This Error Happen?

Node.js uses modules to organize code. When you write require('stripe'), Node looks for the Stripe package in the node_modules folder. If it is not there, you get the error. Common reasons include:

  • The Stripe package was never installed.
  • The package was installed globally instead of locally.
  • You are running the script from the wrong directory.
  • The package.json file is missing or corrupted.

Step 1: Install the Stripe Package

The most common fix is to install Stripe in your project. Open your terminal and navigate to your project folder. Then run:


npm install stripe

This command downloads the Stripe package and adds it to node_modules. It also updates your package.json file. After installation, try running your script again.


node app.js

If the error is gone, you are done. If not, move to the next step.

Step 2: Check Your Working Directory

Sometimes you run your script from the wrong folder. Node.js looks for node_modules in the current directory and its parents. If you are not in the project root, the module will not be found.

Use the pwd command on Linux or Mac, or cd on Windows to check your path. Ensure you are in the folder that contains package.json. If not, change to the correct directory.


# Check current directory
pwd
# Navigate to project root
cd /path/to/your/project

Then run your script again. This simple check often solves the issue.

Step 3: Verify package.json

Your package.json file must list Stripe as a dependency. Open the file and look for a dependencies section. It should look like this:


{
  "name": "my-payment-app",
  "version": "1.0.0",
  "dependencies": {
    "stripe": "^14.0.0"
  }
}

If the entry is missing, add it manually. Then run npm install to install all dependencies. This ensures Stripe is properly linked.

If you have a corrupt package.json, delete it and create a new one with npm init -y. Then install Stripe again.

Step 4: Reinstall Node Modules

Sometimes the node_modules folder gets corrupted. The best fix is to delete it and reinstall everything. Run these commands:


# Remove node_modules folder
rm -rf node_modules
# Remove package-lock.json (optional but helpful)
rm package-lock.json
# Reinstall all dependencies
npm install

This gives you a fresh start. After that, try running your app again. Most errors are fixed by this step.

Step 5: Use the Correct Require Statement

Make sure you are using the right import syntax. In older Node.js versions, use require. In newer versions with ES modules, use import. Here is an example:


// CommonJS (default)
const stripe = require('stripe');

// ES Modules (if you set "type": "module" in package.json)
import Stripe from 'stripe';
const stripe = new Stripe('sk_test_...');

If you mix these, Node.js might not find the module. Check your package.json for the "type" field. If it says "module", use import. Otherwise, use require.

Step 6: Check for Global Installation

Installing Stripe globally with npm install -g stripe is a common mistake. Global packages are not available for local projects. Always install Stripe locally in your project folder.

To check if you have a global version, run:


npm list -g stripe

If it shows a version, uninstall it globally and install it locally:


npm uninstall -g stripe
npm install stripe

This ensures your project uses the correct package.

Step 7: Use a Package Manager Lock File

If you are working in a team, the package-lock.json file ensures everyone uses the same package version. Delete it only when you want to update all packages. Otherwise, keep it to avoid version mismatches.

After reinstalling, commit the lock file to your version control. This prevents the error from appearing on other machines.

Example Code with Comments

Here is a complete example of a Stripe integration that should work after fixing the error:


// Load the Stripe module
const stripe = require('stripe'); // Ensure this line is correct

// Initialize Stripe with your secret key
const stripeClient = stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc');

// Example: Create a payment intent
async function createPayment() {
  try {
    const paymentIntent = await stripeClient.paymentIntents.create({
      amount: 2000, // Amount in cents ($20.00)
      currency: 'usd',
      payment_method_types: ['card'],
    });
    console.log('Payment Intent created:', paymentIntent.id);
  } catch (error) {
    console.error('Error:', error.message);
  }
}

createPayment();

If you run this script after fixing the error, you should see output like:


Payment Intent created: pi_3Oc...secret

If you still see the module error, review the steps above. Also, check for typos in the module name. It must be 'stripe' exactly, not 'Stripe' or 'stripejs'.

Related Troubleshooting

If you encounter other module errors, check our guide on Fix Node.js Error: Cannot find module. It covers general solutions for missing packages. The same principles apply to Stripe.

Another common issue is permission errors. If you get EACCES during installation, use sudo npm install stripe on Linux or Mac. On Windows, run your terminal as administrator.

Conclusion

The Cannot find module 'stripe' error is frustrating but easy to fix. Always install Stripe locally in your project folder. Check your working directory and package.json file. If needed, delete and reinstall node_modules. Use the correct require syntax for your project type. These steps will get your app running again.

Remember to keep your dependencies updated. Run npm update regularly to avoid version conflicts. With these tips, you can focus on building great payment features instead of debugging module errors.