简体   繁体   中英

NPM cannot install packages, cites missing package.json

I'm doing the AWS beginner course and one of the main steps is to install the CDK toolkit for AWS-CLI, and the only given method to do so is by using NPM. I'm not a dev, and totally new to this side of computing, but I used a tutorial and downloaded node.js along with npm, and copy pasted:

npm install -g aws-cdk

It gives me this error each and every time:

    Error: Cannot find module '../package.json'
Require stack:
- C:\Users\darth\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\darth\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
←[90m    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)←[39m
←[90m    at Function.Module._load (node:internal/modules/cjs/loader:778:27)←[39m
←[90m    at Module.require (node:internal/modules/cjs/loader:1005:19)←[39m
←[90m    at require (node:internal/modules/cjs/helpers:102:18)←[39m
    at module.exports (C:\Users\darth\AppData\Roaming\npm\node_modules\←[4mnpm←[24m\lib\cli.js:15:21)
    at Object.<anonymous> (C:\Users\darth\AppData\Roaming\npm\node_modules\←[4mnpm←[24m\bin\npm-cli.js:2:25)
←[90m    at Module._compile (node:internal/modules/cjs/loader:1103:14)←[39m
←[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)←[39m
←[90m    at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m {
  code: ←[32m'MODULE_NOT_FOUND'←[39m,
  requireStack: [
    ←[32m'C:\\Users\\darth\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js'←[39m,
    ←[32m'C:\\Users\\darth\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'←[39m
  ]
}

I've tried reinstalling the node.js, I've tried npm init, I created package.json files for both default and aws-cdk files, and even repairing NPM, to no avail. Does anyone have any insight into this? Thank you!

If you have node and npm installed.

You need to create a folder. This folder will be your project. Let's assume you created a folder called myProject.

This can be achieved in the command line by running this command:

mkdir myProject

In a terminal, you need to navigate to that folder

cd /path/to/your/folder 

Run this command to generate a package.json file.

npm init

From the root of your project. This will generate a package.json file.

Feel free to use the default values.

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