Npm init y ошибка

Это в PowerShell
\Desktop\Trade 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
\Desktop\Trade bot>npm init -y
‘npm’ is not recognized as an internal or external command,
operable program or batch file.


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

  • 3182 просмотра

введите сюда описание изображения

Не получается запустить git init в VS Code, выдаёт сбой. Node.js я скачал.

Подскажите, пожалуйста, что не так. Может дело в плагинах или неправильной установке.

3

VS Code нуждается в пути установки Node.js в системных переменных PATH. Добавьте C:\Program Files\nodejs в PATH.

Подробный гайд с картинками

Dmitry's user avatar

Dmitry

7,66312 золотых знаков25 серебряных знаков53 бронзовых знака

ответ дан 7 июл 2022 в 10:10

Konst's user avatar

KonstKonst

1,9381 золотой знак11 серебряных знаков9 бронзовых знаков

Сначала проверьте работают ли команды npm в терминале Если нет, то думаю следует переустановить node.js. Но если команды работают, то попробуйте через Windows PowerShell(администратор) написать это Set-ExecutionPolicy Unrestricted -Scope CurrentUser и потом ответить yes Чтоб найти Windows PowerShell(администратор) для тех кто не может найти, к иконке значка Пуск подводите мышь и нажимаете правую кнопку мыши и появится окно там можете выбрать Windows PowerShell(администратор) Этот метод помог мне исправить такую ошибку

ответ дан 22 ноя 2022 в 20:40

Оля's user avatar

1

Выдавало такую же ошибку в терминале VS Code. Попробовал ввести команды node -v и npm -v в powershell они у меня сработали. Потом перезагрузил компьютер. Запустил VS Code и у меня получилось в терминале выполнить команду npm init -y.

ответ дан 10 сен в 12:10

Alvin020's user avatar

I encountered the same problem and found the cause and a simple solution.

After installing nvm in bash a few months ago, I recently decided to give zsh and on-my-zsh a try. I followed the instructions and installed zsh and oh-my-zsh. When trying to run node or npm I got the errror:

zsh: /mnt/c/Program Files/nodejs/npm: bad interpreter: /bin/sh^M: no such file or directory

My investigations led me to the $PATH variable. I then compared the output of echo $PATH in bash and zsh. In bash the path included the nvm directory, in zsh this directory was not added to the path.

The reason for this difference is that nvm adds a snippet to the end of .bashrc. In zsh .zshrc is loaded instead and the snippet will not be executed.

The snippet looks like this:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

You can just copy these lines from .bashrc to the end of .zshrc, restart the shell, and the issue should be fixed if you have the same problem.

Problem Description:

I’ve not been using node for a little bit ~1-2 months. It used to work fine before and yet even though I haven’t updated anything etc. I can’t do npm init.

I try to init npm LTS(16). However I get the following error
(init without -y doesn’t work either):

> npm init -y
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:UsersantonDesktopProjectsTextAdventurespackage.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:UsersantonDesktopProjectsTextAdventurespackage.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

Both node and npm report versions just fine:

> node -v
v16.17.1
> npm -v
8.19.2

Error log at (C:UsersantonAppDataLocalnpm-cache_logs2022-10-08T23_17_17_242Z-debug-0.log):

0 verbose cli C:Program Filesnodejsnode.exe C:UsersantonAppDataRoamingnpmnode_modulesnpmbinnpm-cli.js
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:C:UsersantonAppDataRoamingnpmnode_modulesnpmnpmrc Completed in 1ms
6 timing config:load:builtin Completed in 2ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 1ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:C:Usersanton.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:C:UsersantonAppDataRoamingnpmetcnpmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:validate Completed in 0ms
15 timing config:load:credentials Completed in 1ms
16 timing config:load:setEnvs Completed in 1ms
17 timing config:load Completed in 10ms
18 timing npm:load:configload Completed in 10ms
19 timing npm:load:mkdirpcache Completed in 1ms
20 timing npm:load:mkdirplogs Completed in 0ms
21 verbose title npm init
22 verbose argv "init" "--yes" "--unsafe-perms"
23 timing npm:load:setTitle Completed in 1ms
24 timing config:load:flatten Completed in 3ms
25 timing npm:load:display Completed in 4ms
26 verbose logfile logs-max:10 dir:C:UsersantonAppDataLocalnpm-cache_logs
27 verbose logfile C:UsersantonAppDataLocalnpm-cache_logs2022-10-08T23_17_17_242Z-debug-0.log
28 timing npm:load:logFile Completed in 5ms
29 timing npm:load:timers Completed in 0ms
30 timing npm:load:configScope Completed in 0ms
31 timing npm:load Completed in 21ms
32 silly logfile start cleaning logs, removing 4 files
33 silly logfile done cleaning log files
34 silly package data {
34 silly package data   name: 'textadventures',
34 silly package data   version: '1.0.0',
34 silly package data   description: '',
34 silly package data   main: 'index.js',
34 silly package data   scripts: { test: 'echo "Error: no test specified" && exit 1' },
34 silly package data   keywords: [],
34 silly package data   author: '',
34 silly package data   license: 'ISC'
34 silly package data }
35 timing command:init Completed in 24ms
36 verbose stack Error: ENOENT: no such file or directory, open 'C:UsersantonDesktopProjectsTextAdventurespackage.json'
37 verbose cwd C:UsersantonDesktopProjectsTextAdventures
38 verbose Windows_NT 10.0.22000
39 verbose node v16.17.1
40 verbose npm  v8.19.2
41 error code ENOENT
42 error syscall open
43 error path C:UsersantonDesktopProjectsTextAdventurespackage.json
44 error errno -4058
45 error enoent ENOENT: no such file or directory, open 'C:UsersantonDesktopProjectsTextAdventurespackage.json'
46 error enoent This is related to npm not being able to find a file.
46 error enoent
47 verbose exit -4058
48 timing npm Completed in 198ms
49 verbose code -4058
50 error A complete log of this run can be found in:
50 error     C:UsersantonAppDataLocalnpm-cache_logs2022-10-08T23_17_17_242Z-debug-0.log

I’m running Windows 11 (21H2).

My paths are:

NODE
C:Program Filesnodejs

NPM
C:UsersantonAppDataRoamingnpm

What I’ve tried from other Stack Overflow posts:

  1. Starting cmd in administrator
  2. Running init with --unsafe-perms
  3. Deleting npm path (C:UsersantonAppDataRoamingnpm)
  4. Restarting my pc
  5. npm i -g --force
  6. npm cache verify
  7. Creating the package.json myself (Causes similar enoent open errors when installing modules)
  8. Reinstalling node (NOTE: I didn’t uninstall node I just ran the newest installer however I doubt it changes much?)
  9. Something along the lines of cache clear. (Don’t remember the exact command and no logs since I restarted my computer)

These are all the solutions I’ve found through some digging online. None of them have worked.

Solution – 1

After some tinkering I found out that even though Windows Defender doesn’t mention anything, its Controlled Folder Access blocks npm from creating/reading files.

So the solution to my problem is to turn off Controlled Folder Access or add an exclusion for npm.

  1. What is npm init?
  2. Why is npm start not working?
  3. What is npm init y?
  4. What does npm run start do?
  5. Why do I need npm init?
  6. Do I need npm init?
  7. How do I run npm?
  8. Why npm is not working in VS code?
  9. What is yarn init?
  10. Does npm init create a directory?

What is npm init?

Description. npm init <initializer> can be used to set up a new or existing npm package. initializer in this case is an npm package named create-<initializer> , which will be installed by npx , and then have its main bin executed — presumably creating or updating package.

Why is npm start not working?

If you type npm start and get the npm err! missing script: start error, there must be a missing line in the script object located in your package. json file. The error also tells us that the missing content is in regards to the start command.

What is npm init y?

npm init -y. will simply generate an empty npm project without going through an interactive process. The -y stands for yes .

What does npm run start do?

npm start: npm start script is used to execute the defined file in it without typing its execution command.

Why do I need npm init?

Most developers run npm init right after creating and navigating into a new project. It makes sense to npm init at the start of the project because we use npm to download dependencies. Once we npm init , we can begin downloading (and saving) our dependencies. For most projects, this workflow works.

Do I need npm init?

It is not required. You can install packages without, and everything will work. npm init can do basically two things: ask for basic project info to include in packages.

How do I run npm?

Add the Run npm command Step to your Workflow preceding any build Step. Set the Working directory. Set the command you want npm to execute, for example install to run npm install in the The npm command with arguments to run input.

Why npm is not working in VS code?

This is because New VSCode runs with user privileges. Your Nodejs installation added npm’s path as System variable which VSCode cannot read. Adding NPM path to Path variable in the User variable, you will be able to run NPM from the integrated command line.

What is yarn init?

The yarn init command is a command used to create or update a package. json file interactively. yarn init. when you run this command from the terminal, it will walk you through an interactive session to create a package.

Does npm init create a directory?

When set for the npm init command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.

Понравилась статья? Поделить с друзьями:
  • Npm err code enoent ошибка
  • Nvoglv64 dll ошибка видеодрайвера
  • Np 41372 7 ps4 ошибка
  • Nvoglv32 dll ошибка
  • Nvme sys ошибка