简体   繁体   中英

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

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM