Vue Cli: Cannot find module '../package.json' error after npm install
Asked Answered
E

3

18

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

Elisabetta answered 27/1, 2019 at 10:1 Comment(3)
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.Semi
@Semi +1 please post as an answerHarrie
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.Kerbing
I
51

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.

Immunogenetics answered 8/5, 2019 at 11:51 Comment(4)
How about build offline in another server with different path?Fablan
Please note that npm i does not do a full install. The above answer is the recommended way of solving this issue.Jolson
Thank you, I experienced the same problem after duplication the project folderTajo
npm rebuild works too without requiring a whole fresh installScottie
D
0

I encountered the exact same issue when I was attempting to zip my Vue application using the command:

zip -r myzip.zip node_modules/ dist/ etc...

After moving the zip to a different location, extracting it, and then trying to run the app, it didn't work as expected.

The root cause of the problem turned out to be related to the node_modules/.bin directory. This directory contained bunch of symlinks which were not added to the zip file, including a symlink for the vue-cli-service:

vue-cli-service -> ../@vue/cli-service/bin/vue-cli-service.js

That file imported the package.json file located in the node_modules/@vue/cli-service/ directory. The improper handling of this symlink during the zipping process resulted in the app not being able to run after extraction (due to the lack of package.json in the aforementioned directory).

To resolve this issue I had to to use -y flag for zip command, so it handles symlinks properly. I guess this can be related to your issue. Make sure you're copying symlinks properly when moving Vue project.

Dissoluble answered 12/2 at 12:46 Comment(0)
B
0

Check Node and npm versions. If not, you can try to delete node_modules due corrupted dependencies. Also you can try other terminals to test if the issue persists.

Britishism answered 12/2 at 13:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.