Error in running nuxt project: "'nuxt' is not recognized as an internal or external command"
Asked Answered
P

9

35

When I tried to run npm run dev in my nuxt project, my console returned this message:

'nuxt' is not recognized as an internal or external command, 
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `nuxt`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Pena answered 6/5, 2019 at 1:37 Comment(4)
What version of node, npm and nuxt do you have?Lelea
Have you run npm install?Goldschmidt
I tried run npm install alrady. [email protected] node v10.15.3 npm 6.4.1Pena
Possible duplicate of npm ERR! code ELIFECYCLEIdolah
P
88

I solved this problem.
I was looking in stackoverflow for similar problems and apparently the problem was the npm cache.
I will let a link bellow with the solution and a quick sample of what i did.

Link to the answer: npm ERR! code ELIFECYCLE

Step 1: npm cache clean --force

Step 2: Delete node_modules by $ rm -rf node_modules folder or delete it manually by going into the directory and right-click > delete. Delete package-lock.json file too.

Step 3: npm install

To start again, npm start

Thanks everyone who take time to help, really appreciate.

Pena answered 10/5, 2019 at 1:45 Comment(1)
This answer also solved the similar problem I had with nuxt-ts. Thank you !Fichtean
I
16

Make sure nuxt is installed in your Nuxt project:

$ cd /path/to/nuxt-project
$ npm list nuxt
[email protected] /path/to/nuxt-project
└── [email protected] 

Here /path/to/nuxt-project contains your package.json and node-modules.

If it isn't installed, add nuxt to your project by doing:

$ npm install --save nuxt

Or put it in your project's package.json then do npm install:

  "dependencies": {
    "nuxt": "^2.0.0"
  },

UPDATE:
If you are still getting "nuxt not recognized" problems, try to use explicit path to nuxt from your node_modules directory.

Given this directory (after doing npm install --save nuxt):

nuxt-project
|- node_modules
   |- .bin
      |- nuxt
|- package.json

Update the dev command in package.json with:

"scripts": {
  "dev": "node_modules/.bin/nuxt"
},
Idolah answered 6/5, 2019 at 2:40 Comment(5)
It still has the same error. My dependencies: "dependencies": { "nuxt": "^2.4.0", "cross-env": "^5.2.0", "bootstrap-vue": "^2.0.0-rc.11", "bootstrap": "^4.1.3", "@nuxtjs/axios": "^5.3.6" },Pena
@Pena Just to be sure, you are running npm install and npm run dev under the project directory? What do you get when you do npm list nuxt?Idolah
I am sure that i'm on the right directory.and when i run npm list nuxt i get this: `-- [email protected] I search on google and i found some people having problems with nuxt + windows 10Pena
@Pena Oh OK. I updated my answer. Try to change the dev command to use the explicit node_modules path for nuxt.Idolah
I followed these steps and this error went away for me. But, I had to use yarn install after this to link the dependencies properly and do npm run devEndaendall
F
10

Sometimes this blows up because you're not exporting node_modules/.bin directory.

Place or append the following line in your .bashrc or .zshrc:

export PATH=node_modules/.bin:$PATH

Feaze answered 29/10, 2019 at 9:53 Comment(0)
M
3

Have the same problem recently.

Solution for me was change the path of scripts section in package.json from this:

  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate"
  },

to that:

  "scripts": {
    "dev": "node_modules/.bin/nuxt",
    "build": "node_modules/.bin/nuxt build",
    "start": "node_modules/.bin/nuxt start",
     "generate": "node_modules/.bin/nuxt generate"
  },
Mcculloch answered 7/12, 2020 at 11:40 Comment(0)
A
1
  • Step 1: rm -rf node_modules package-lock.json

  • Step 2: npm cache clean --force

  • Step 3: npm install ( you may need to add --legacy-peer-deps or --force flag, if npm install is not working )

  • To start again, npm start

  • To make build, npm run build (ssr ) or generate ( csr )

Accursed answered 21/2, 2023 at 7:28 Comment(0)
I
0

Migrating from Nuxt 2 to Nuxt 3?

Change your scripts in package.json to not refer to nuxt-ts anymore, but just to nuxt instead. Example: "dev": "nuxt-ts", -> "dev": "nuxt dev",, "generate": "nuxt-ts generate", -> "generate": "nuxt generate",, etc.

Ib answered 8/4, 2023 at 9:11 Comment(0)
S
0

after installing the project. You need to install packages in package.json

Suez answered 3/8, 2023 at 15:38 Comment(0)
P
-3

It simply means nuxt is not installed.

Try running npm install nuxt

Pericarditis answered 29/8, 2021 at 3:39 Comment(0)
C
-4

Install globally cross-env: npm install -g cross-env

Then just update package.json scripts to start with "cross-env ...."

example:

"scripts": {
    "dev": "cross-env nuxt",
    "build": "cross-env nuxt build",
    "start": "cross-env nuxt start",
    "generate": "cross-env nuxt generate",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore ."
},

This works on my Windows 10.

Currier answered 1/10, 2019 at 19:10 Comment(1)
what does cross-env have to do with nuxt being undefined?Valetudinary

© 2022 - 2024 — McMap. All rights reserved.