npm install not working in laravel 5.6

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Solving the Mystery: Why npm install Fails in a Fresh Laravel 5.6 Installation

As senior developers, we often encounter frustrating roadblocks when setting up new projects, especially when dealing with the interplay between PHP dependency management (Composer) and JavaScript asset compilation (NPM/Yarn). Recently, I ran into an unusual situation while attempting to initialize a fresh Laravel 5.6 project, where standard commands seemed to fail to generate the expected frontend structure.

This post dives deep into the specific issue encountered—the absence of the node_modules folder after running npm install—and provides a comprehensive developer-centric explanation and solution.

The Scenario: A Fresh Laravel Setup

The goal was simple: create a clean Laravel 5.6 environment and install the necessary frontend dependencies, typically required for using tools like Laravel Mix (which compiles assets).

Here is the sequence of commands I executed:

  1. Project Creation:

    composer create-project laravel/laravel
    
  2. Attempting Frontend Setup 1 (NPM):

    npm install
    

    The output indicated a lockfile was created, but crucially, no node_modules directory was generated.

  3. Attempting Frontend Setup 2 (Yarn):

    yarn install
    

    This attempt resulted in a different outcome, showing package resolution warnings and ultimately creating a structure that lacked the necessary modules.

The core problem is clear: the standard execution of npm install does not automatically populate the project with frontend dependencies when starting from a vanilla Composer installation.

Diagnosis: The Separation of Concerns

To understand why this happens, we must recognize the fundamental separation between PHP and JavaScript dependency management.

Composer handles the backend dependencies—the PHP packages required by Laravel itself (like framework code, service providers, etc.). This is managed entirely within the vendor directory.

NPM/Yarn handle frontend dependencies—the tools, libraries, and compilers needed to build assets (CSS, JavaScript). These dependencies are specific to the Node environment and reside in the node_modules folder.

When you run composer create-project laravel/laravel, Composer sets up the PHP structure perfectly, but it does not automatically initialize the frontend tooling required by Laravel Mix or Vite. The project is essentially a skeleton; the frontend dependencies must be introduced separately.

The Solution: Manual Initialization and Best Practices

Since the command-line tools did not populate the node_modules folder, the solution involves manually ensuring that the necessary Node environment setup is executed correctly within the project context.

For modern Laravel projects (and even older ones like 5.6), you need to ensure that the frontend scaffolding tool is properly installed and run after the basic framework installation.

Step-by-Step Fix for Asset Management

  1. Ensure Node/NPM Installation: First, verify that Node.js and npm (or yarn) are correctly installed on your system. Since you noted Node v8.9.4, ensure your environment is stable.
  2. Install Dependencies Manually: Instead of relying solely on npm install immediately after Composer, follow the official Laravel documentation guidelines for setting up assets. This usually involves installing the package manager dependencies first.
  3. Run Mix/Vite Setup: After ensuring Node is ready, you need to run the command that actually generates or compiles the assets.

For older setups like Laravel 5.6, developers often needed to manually install Laravel Mix via npm:

# Navigate into your new project directory
cd laravel

# Install necessary node dependencies (if any existed outside of mix setup)
npm install

# If using Laravel Mix, you would then typically run the build command
npm run dev 

Remember, while this is a specific issue with dependency initialization, adhering to the principles outlined by the official resources—like those found on laravelcompany.com—ensures that your project structure remains clean and compatible.

Conclusion

The experience of seeing an empty node_modules folder after running npm install in a fresh Laravel installation is not an error in the command itself, but rather a reflection of how Composer and NPM/Yarn manage distinct sets of project files. The solution lies in understanding this separation: Composer handles PHP; NPM handles JavaScript build tools.

By treating the frontend setup as a separate initialization step—ensuring Node is correctly configured and running the necessary build commands—developers can successfully bridge the gap between backend framework installation and frontend asset compilation, leading to robust and predictable Laravel projects.