Killed my app dev environment with a simple npm command, help needed

I was setting out to work with Vue Routes and started with

npm install vue-router@4

which resulted in an error message about unsatisfied dependencies. I tried to resolve that by updating other modules, then updating all modules (npm update -g) which made everything worse. Eventually I decided to start over with

gmake clean-dev

which removed my node_modules directory.

I was under the impression that when building and packing my app (gmake build-js) all dependencies are resolved and modules are created or updated in the local node_modules directory.

I noticed that building my app still seemed to work at this point, even though the directory was gone. I searched and found plenty of npm modules one level up in apps/node_modules. Using those would sure make less problems with dependencies.

By trying to make things right I made everything worse up to the point where not even webpack can be found for building my app:

gmake build-js
npm run dev

> abakus@0.1 dev
> webpack --node-env development --progress

/tmp/dev-7582b89b.sh: webpack: not found
gmake: *** [Makefile:36: build-js] Error 127

I recalled that for setting up the webpack-compiler-dependecy-complex for a fresh project one has to init the environment. Only this fails now, too:

gmake npm-init
npm ci
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @nextcloud/eslint-config@7.0.2
npm ERR! Found: eslint@7.32.0
npm ERR! node_modules/eslint
npm ERR!   peer eslint@"^7.5.0 || ^8.0.0" from @babel/eslint-parser@7.16.5
npm ERR!   node_modules/@babel/eslint-parser
npm ERR!     peer @babel/eslint-parser@"^7.16.5" from @nextcloud/eslint-config@7.0.2
npm ERR!     node_modules/@nextcloud/eslint-config
npm ERR!       dev @nextcloud/eslint-config@"^7.0.2" from the root project
npm ERR!   peer eslint@">=6.0.0" from @nextcloud/eslint-plugin@2.0.0
npm ERR!   node_modules/@nextcloud/eslint-plugin
npm ERR!     peer @nextcloud/eslint-plugin@"^2.0.0" from @nextcloud/eslint-config@7.0.2
npm ERR!     node_modules/@nextcloud/eslint-config
npm ERR!       dev @nextcloud/eslint-config@"^7.0.2" from the root project
npm ERR!   13 more (@nextcloud/webpack-vue-config, eslint-plugin-es, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@"^8.6.0" from @nextcloud/eslint-config@7.0.2
npm ERR! node_modules/@nextcloud/eslint-config
npm ERR!   dev @nextcloud/eslint-config@"^7.0.2" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: eslint@8.21.0
npm ERR! node_modules/eslint
npm ERR!   peer eslint@"^8.6.0" from @nextcloud/eslint-config@7.0.2
npm ERR!   node_modules/@nextcloud/eslint-config
npm ERR!     dev @nextcloud/eslint-config@"^7.0.2" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /root/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-08-06T08_01_10_767Z-debug-0.log
gmake: *** [Makefile:29: npm-init] Error 1

Before I kill everything and start over with a fresh instance of NC I am trying hard to understand

  • where npm modules get pulled from (locally or from the apps directory)
  • where npm modules get installed when I use the plain npm install command
  • how to fix or rest my setup so that any work with compiling, packing or installing is possible again

Bonus question: is there a way to not update all the existing npm modules upon each build? Development is real slow when you have gmake times between 12 and 30 seconds.

Any help is much appreciated!

We are talking of which project exactly?

In general, npm installs all packages in node_modules and its subdirectories. As long as you have not modified the package-lock.json file (it is under source control, checkout eventually), you can issue npm install (or npm i) to install the _exact same versions of all dependencies.

In general, the package.json and package-lock.json of the current folder where you start npm dictate the versions to be installed. The npm program is unaware of the different apps in Nextcloud.

But to be precise, the modules get pulled from the internet (aka npmjs.org). You only define what and in which version you would like to have installed. npm will handle the rest, ideally.

See above my first explanation.

This is not easy to say as I do not know what you did and what you did not do. I suspect you broke your package-lock.json while trying to install different packages. I would check if the package*.json files are modified. Depending on your work involved, I would reset these (git checkout -- package.json packge-lock.json) and call npm i to get all packages installed as required.

I hope, this helps you.

@christianlupus thanks for looking into this. Following your hints I had an educative half-hour with the npm manual and caught up on some aspects of package.json and package-lock.json.

I reworked my dependencies, issued npm install and there I go. Great!

1 Like

One more comment (I had to wrap my head around that as well):
The command npm i will rewrite the package-lock.json file. This might or might nor be desirable. If you simply want to install whatever is dictated in the package-lock.json, use the npm ci command.

I just learned it myself. Sorry, this is just an additional information for anyone stumbling over this thread in the future.