17

I am not an expert in Vuejs or Vuecli, but I do manage to get stuff working. I had a project i worked on before using Vuecli3 and webpack and now when I opened it after few weeks to make changes, i get the below error in dev mode

$ vue-cli-service serve --open --mode development --dashboard
internal/modules/cjs/loader.js:582
    throw err;
    ^

Error: Cannot find module '../package.json'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Volumes/Drobo/Dropbox/NASDAQ Dubai/Marketdata-6-Indices/node_modules/.bin/vue-cli-service:5:25)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)

Total task duration: 0.15s

The package.json file is right there in the root director and also the .lock file. Dont know what is the reason for this error in compiling.

Any help hightly appreciated

amucunguzi
  • 1,203
  • 1
  • 12
  • 16
Jenos
  • 485
  • 1
  • 4
  • 15
  • 6
    I experienced the same problem after moving the folder to a new location. Running 'yarn' or 'npm install' again makes the problem go away in my case. – vesperknight Mar 16 '19 at 15:40
  • @vesperknight +1 please post as an answer – xlm Apr 12 '19 at 01:06
  • Super obscure/stupid, but might help someone: I ran into this when I accidentally ran vue cli in a network mounted path. Which is essentially similar to "moving the folder", I guess. – kubi Aug 26 '22 at 17:39

1 Answers1

50

As @vesperknight mentioned in the comment, this issue tends to happen when you move the project's folder to another location.

To solve this (on Linux), from the root directory of your project:

  1. Delete existing node modules. rm -r node_modules

  2. Reinstall all dependencies: npm install

The first step seems to be important.

amucunguzi
  • 1,203
  • 1
  • 12
  • 16