Home > Enterprise >  Node/NPM is updating package.json and package-lock.json file in my home directory instead of project
Node/NPM is updating package.json and package-lock.json file in my home directory instead of project

Time:04-18

I want to play around with a simple babylonjs toy project and I created a directory on my computer for it at ~/workspace/babylon-test. I then navigate to that directory. So the commands look like this:

mkdir ~/workspace/babylon-test
cd ~/workspace/babylon-test

I use pwd to verify that I am currently inside the babylon-test directory.

I run the following command, recommended from the Babylon docs, to install the babylonjs modules:

npm install babylonjs --save

I go to inspect my current directory (babylon-test) and it's empty:

$ pwd
/Users/myuser/workspace/babylon-test
$ ls -al
total 0
drwxr-xr-x   2 myuser  staff    64 Apr 18 13:05 .
drwxr-xr-x  47 myuser  staff  1504 Apr 18 13:05 ..

However, it seems package.json and package-lock.json were created or updated in my home directory:

$ ls -al ~
total 22720
drwxr-xr-x  137 myuser  staff     4384 Apr 18 12:58 .
drwxr-xr-x    5 root     admin      160 Apr  9  2018 ..
<lots of files and subdirectories listed here, omitting for brevity and scope>
drwxr-xr-x  780 myuser  staff    24960 Apr 18 21:20 node_modules
-rw-r--r--    1 myuser  staff   896008 Apr 18 21:14 package-lock.json
-rw-r--r--    1 myuser  staff      148 Apr 18 13:06 package.json

Looking at ~/package.json I see its contents are:

{
  "devDependencies": {
    "@vue/cli-plugin-router": "~4.5.0",
    "electron": "^13.1.4"
  },
  "dependencies": {
    "babylonjs": "^5.2.0"
  }
}

I remember trying to install Vue and the Vue CLI several months ago, and I'm wondering if I messed up my Node/NPM configuration somehow.

Shouldn't I see a package.json and package-lock.json file be generated inside my /workspace/babylon-test directory? And not in my homedir? If so, what can I do to troubleshoot and see what's going on?

CodePudding user response:

Run npm init first on your pwd and then do npm install Ref: https://docs.npmjs.com/cli/v8/commands/npm-init

CodePudding user response:

A package.json file needs to exist for NPM to install packages. Run npm init -y to quickly create a package.json. Then when you run npm install it'll append it to the dependencies array in your package.json and install the dependencies to the node_modules folder of your project.

  • Related