Having trouble installing npm on my Laradock environment

After setting up a Laravel project with Laradock, running npm install resulted in the following error:

> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f31303b3a722c3e2c2c1f6b7166716f">[email protected]</a> install /var/www/npmtest/node_modules/node-sass
> node scripts/install.js

fs.js:119
    throw err;
    ^

Error: EINVAL: invalid argument, open '/var/www/npmtest/node_modules/node-sass/package.json'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:348:35)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:719:20)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/var/www/npmtest/node_modules/node-sass/lib/extensions.js:7:9)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
npm WARN rollback Rolling back <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec859fc18a9980809b85889884c18f838889c19c83858298acddc2dcc2dc">[email protected]</a> failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/gauge/node_modules/is-fullwidth-code-point'
npm WARN rollback Rolling back <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e28b91cf84978e8e958b86968acf818d8687cf928d8b8c96a2d3ccd2ccd2">[email protected]</a> failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/sass-graph/node_modules/is-fullwidth-code-point'
npm WARN rollback Rolling back <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7c1f141d10173c4d524d524f">[email protected]</a> failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/node-sass/node_modules/chalk'
npm WARN rollback Rolling back <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="394a4d4b50575e144e505d4d5179081709170b">[email protected]</a> failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/gauge/node_modules/string-width'
npm WARN rollback Rolling back <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5c3f343d30371c6d726d726f">[email protected]</a> failed (this is probably harmless): ENOTEMPTY: directory not empty, rmdir '/var/www/npmtest/node_modules/har-validator/node_modules/chalk'
npm WARN rollback Rolling back <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="375644445245431a475b4244770619071907">[email protected]</a> failed (this is probably 

..... ..... .....

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e284918794878c9691a2d3ccd0ccd6">[email protected]</a> (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b5d485e4d5e554f487b0a1509150f">[email protected]</a>: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7b9b8b3b2faa4b6a4a497e3f9eef9e7">[email protected]</a> install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="432d2c27266e3022303003776d7a6d73">[email protected]</a> install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-06-22T04_51_41_566Z-debug.log

The npm install command failed to run as expected within the Laravel project set up using Laradock, while projects created outside the Docker environment worked seamlessly. Can someone provide insight into this issue?

Answer №1

I encountered a similar issue recently. It's hard to pinpoint when the problem started because I used to run npm install on this project, but there's a chance I might have used yarn install instead, which seemed to work fine.

However, since we wanted to stick with npm, I had to find a solution for this issue.

The problem seems to be related to mounting volumes using CIFS 3.02 rather than CIFS 2.0 in Laradock. This issue is discussed on the docker for windows github repository.

Although I'm not an expert in docker, I managed to resolve the issue by updating the docker-compose.yml file to create a volume using CIFS 2.0.

To do this, simply add a new volume under the volumes: section and name it (e.g., code).

If you are using Laradock version >= 7.0.0, the volume configuration is located near the top of the docker-compose.yml file; if you are using a lower version, it will be at the bottom.

Since the volume definition is external to the build contexts, you'll need to specify the path to your code directly in the docker-compose.yml file.

Your updated volumes: section should look like this:

volumes:
  mysql:
    driver: ${VOLUMES_DRIVER} (or "local")
  percona:
    driver: ${VOLUMES_DRIVER} (or "local")
  [other volumes removed for brevity...]
  code:
    driver: "local"
    driver_opts:
      type: cifs
      device: //10.0.75.1/C/path/to/your/code/
      o: "rw,relatime,vers=2.0,sec=ntlmsspi,cache=strict,username=[your user name],password=[your password],domain=[your domain, if any; otherwise remove this],uid=0,noforceuid,gid=0,noforcegid,addr=10.0.75.1,file_mode=0755,dir_mode=0755,iocharset=utf8,nounix,serverino,mapposix,nobrl,mfsymlinks,noperm,rsize=1048576,wsize=1048576,echo_interval=60,actimeo=1"

Make sure to update the path and credentials accordingly in the volume configuration.

After defining the new volume, update the workspace service to use the newly created volume.

In Laradock version >= 7.0.0, replace ${APP_CODE_PATH_HOST} with the new volume name in the volumes: section of the workspace service.

If using a lower version, update the applications service in a similar manner.

When you start your containers and access the workspace container, the volume should now be mounted using CIFS 2.0. Confirm by running mount | grep cifs.

With the volume properly configured, npm install should work without issues, allowing node-sass's install script to function correctly in locating the package.json file.

Answer №2

I encountered a similar issue with laradock, and although I don't have a solution for NPM, using yarn install should work. Unfortunately, I'm not sure why this problem arises, but hopefully this information is useful to you!

Answer №3

To recreate the workspace container, follow this command:

docker-compose build workspace

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Develop a straightforward static webpage and set it up by installing and launching it using NPM

I am attempting to craft a straightforward HTML page that incorporates CSS/JS and utilizes npm. The objective is to construct a basic page that can be accessed by simply using "npm install" and "npm start". As an example, I will design a page with HTML, ...

broadcast a video file from a Node.js server to multiple HTML5 clients at the same time

After researching online, I have been looking for a way to simultaneously stream a video.mp4 to multiple html5 clients. Despite reading various tutorials, I haven't found the ideal solution using nodejs. Do you have any suggestions or alternative met ...

Adding npm packages to your Vue.js application

My Vue app is structured like this (auto created by vue init webpack myProject): index.html components/ -main.js -App.vue I am trying to include npm packages, such as https://github.com/ACollectionOfAtoms/atomic-bohr-model. Following the instructions, I ...

The issue with using HTML code inside a variable that is passed into a partial view is that the code is not being

I have created a partial view to show the page header, which takes in two variables - an Icon and a title. The code for pageHeader.blade.php is as follows: <div class="page-header"> <div class="row"> <!-- Page header, center on small sc ...

Parcel JS: The function tree.render is missing or not defined

Every time I attempt to execute the production build command npm run build or npx parcel build index.html, this error occurs. My project consists of simple HTML and CSS, without any React or third-party libraries. What could be causing this issue? I have t ...

What is the best way to add permissions to each role in JavaScript?

I have been attempting to dynamically add data to an HTML table using JavaScript. The data consists of roles and their corresponding permissions, which are retrieved using Laravel's ORM. I have tried utilizing a nested each jQuery function to append t ...

how to toggle a pre-selected checkbox in a Vue component

https://i.stack.imgur.com/6GQl7.png When dealing with a tree view checkbox in Vue, I encountered an issue where editing data within a selected zone should automatically check the corresponding countries based on previous selections. The ID of the selected ...

Consolidate HTML project into a unified HTML file

In my current project, I am working with a static HTML report that is organized in the structure outlined below: 1.css 2.font 3.js 4.pages 5.attachments 6.index.html I would like to know how I can combine all these elements to create a unified 'repor ...

Can I use npm's jQuery in an old-school HTML format?

I am looking to incorporate jQuery into a project without having to rely on the website or CDN for downloading the library. As someone new to npm, I am curious to know if following these steps would be advisable or potentially problematic down the line. Wh ...

Develop a custom script function for every instance of a @foreach loop

I have a challenge where I need to style automatically generated table rows by clicking on a button. Currently, my code appears as follows: @foreach($tours as $tour) <tr id="{{$tour->id}}"> <td> {{$tour->tournr}} &l ...