Npm init y ошибка

This appears when I run the second command

npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for fsevents@1.2.13: wanted {«os»:»darwin»} (current: {«os»:»win32″,»arch»:»x64″})
npm ERR! notsup Valid OS: darwin
npm ERR! notsup Valid Arch: undefined
npm ERR! notsup Actual OS: win32
npm ERR! notsup Actual Arch: x64

npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersUserAppDataLocalnpm-cache_logs2021-04-26T11_48_47_873Z-debug.log

Это в PowerShell
DesktopTrade bot> npm init -y
npm : The term ‘npm’ is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ npm init -y
+ ~~~
+ CategoryInfo : ObjectNotFound: (npm:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Это в cmd
DesktopTrade bot>npm init -y
‘npm’ is not recognized as an internal or external command,
operable program or batch file.


  • Вопрос задан

    более двух лет назад

  • 2982 просмотра

C:UsersUserDesktopWEB DEV>npm init -y
npm ERR! Invalid name: «WEB DEV»

npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersUserAppDataRoamingnpm-cache_logs2020-12-05T13_55_29_054Z-debug.log

C:UsersUserDesktopWEB DEV>

  • javascript
  • npm
  • visual-studio-code

asked Dec 5, 2020 at 14:02

Subrato Kumar Mahato's user avatar

2

  • why you dont jsut write npm init

    Dec 5, 2020 at 15:20

  • Rename the WEB DEV folder as WEB-DEV (i.e. no space character) and try again.

    Dec 5, 2020 at 16:23

1 Answer

answered Dec 5, 2020 at 14:06

keysl's user avatar

keyslkeysl

2,1071 gold badge11 silver badges16 bronze badges

I’m opening this issue because:

  • npm is crashing.
  • npm is producing an incorrect install.
  • npm is doing something I don’t understand.
  • Other (see below for feature requests):

What’s going wrong?

Inside of a folder named FOO, if I run npm init, I get something like the following

Press ^C at any time to quit.
name: (DELETE_ME) 
Sorry, name can no longer contain capital letters.
name: (DELETE_ME) 

if I run npm init -y, I get this

npm init -y 
Wrote to /Users/pdk/projects/Modernizr/DELETE_ME/package.json:

{
  "name": "DELETE_ME",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

How can the CLI team reproduce the problem?

mkdir /tmp/FOO && cd FOO && npm init -y

supporting information:

  • npm -v prints: 3.10.8
  • node -v prints: v6.6.0
  • npm config get registry prints: https://registry.npmjs.org/
  • Windows, OS X, or Linux?: OS X

Cannot find module ‘express’: Install the package by running the command npm install express in the root directory of your project to resolve the error “Cannot find module ‘express’.”

Run npm init -y to generate a package.json file if you don’t already have one.

Output of npm init -y:

Wrote to C:UserscirusDesktopBtechgeekspackage.json:

{
"name": "btechgeeks",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

index.js:

const express =require('express');

const app = express();
const port = 5000;

app.get('/', (req, res) => {
  res.send('Hello This is BTechgeeks!');
});

app.listen(port, () => {
  console.log(`Your app is listening on port ${port}`);
});

Now if we run the above index.js then we get,

PS C:UserscirusDesktopBtechgeeks> node index.js
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module 'express'
Require stack:
- C:UserscirusDesktopBtechgeeksindex.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:UserscirusDesktopBtechgeeksindex.js:1:16)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'C:\Users\cirus\Desktop\Btechgeeks\index.js' ]
}

i.e Cannot find module ‘express’ error.

Node cannot find module express: Below are the ways to fix the above error:

  • Installing express using npm
  • Deleting node modules

Fix #1: Installing express using npm

error: cannot find module ‘express’: Open your terminal in your project’s root directory (the one that contains your package.json file) and perform the following command to ensure you have express installed:

npm install express

Output:

PS C:UserscirusDesktopBtechgeeks> npm install express

added 57 packages, and audited 58 packages in 3s

7 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities

The error should go away once you’ve installed express.

Now when we run index.js we get:

Output(index.js):

Your app is listening on port 5000

Fix #2: Deleting node modules

If the error persists, consider deleting your node modules directory and the package-lock.json file, then re-running npm install and restarting your IDE.

Run the following commands in your terminal in the root directory of your project.

// deleting node_modules and package-lock.json
rm -rf node_modules package-lock.json

// installing all packages in package.json
npm install

If the error persists, be sure to restart your IDE. VSCode has a tendency to crash, and a reboot can occasionally fix the problem.

If you experience any issues after running these commands, consider deleting the node modules and package-lock.json files from the root directory of your project manually.

If a permissions problem occurs, try running the command with sudo, such as

sudo npm install

The express package should now be able to be imported and used.

Now when we run index.js we get:

index.js:

const express =require('express');

const app = express();
const port = 5000;

app.get('/', (req, res) => {
  res.send('Hello This is BTechgeeks!');
});

app.listen(port, () => {
  console.log(`Your app is listening on port ${port}`);
});

Output(index.js):

Your app is listening on port 5000

After installing express our package.json looks like this:

{
  "name": "btechgeeks",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.1"
  }
}

It contains express in dependencies.

Make sure to include the express package to your dependencies object rather than devDependencies.
You can try adding the line manually and re-running npm install.

Command:

npm install

Output:

PS C:UserscirusDesktopBtechgeeks> npm install

added 57 packages, and audited 58 packages in 2s

7 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities

Понравилась статья? Поделить с друзьями:
  • Nox player ошибка сервисов google play
  • Np 38551 2 ошибка ps4
  • Nox player ошибка разблокировки
  • Np 37614 1 ошибка ps4
  • Nox player ошибка при запуске игры