Ligonsker's avatar

Reading node_modules from a dedicated Node.js project

Hello,

Currently Using Laravel 11 and I have node_modules folder inside the project.

But I need to move the node_modules to a separate Node.js - only project and somehow make the Laravel project use the node_modules there.

For example, right now the structure is:

laravel-project
    |______node_modules
              |________some-module
              |________some-other-module

But I need it to be:

laravel-project
nodejs-project
    |______node_modules
              |________some-module
              |________some-other-module

Is such thing possible?

thanks

1 like
5 replies
Ligonsker's avatar

@vincent15000 There is some problem with some ci/cd tools currently which have issues installing node with php together until they figure out how to make it work but in this time this issue became critical to be able to use it like that (if it's even possible)

1 like
Ligonsker's avatar

By the way, where is the path to node_modules configured in the laravel project? I searched in resources/js/app.js and resources/js/bootstrap.js but couldn't find where it's being configured

1 like
vincent15000's avatar

@Ligonsker The path of the node modules are not defined in the Laravel project.

It's related to node and the package.json file.

When you build the assets with npm run build, it creates a build folder inside the public folder and the assets are loaded via @vite([...]) inside the header tags.

You can't move the node_modules folder outside the project folder.

Or if you do this, you need to work with 2 different projects : a frontend and a backend, and communicate between the front and the back with an API.

Please or to participate in this conversation.