nuxt:找不到命令 |必须使用 npx 而不是 npm [英] nuxt: command not found | Having to use npx instead of npm
问题描述
我正在尝试使用 nuxt.js 创建一个 SSG 网站,但是当我尝试运行 nuxt build &&nuxt export
或 VS Code 终端中的任何其他 nuxt 命令我收到此错误:bash: nuxt: command not found
.我已经安装了这些:
I'm trying to create an SSG website with nuxt.js but when I try to run nuxt build && nuxt export
or any other nuxt command in the VS Code terminal I get this error: bash: nuxt: command not found
. I have these installed:
- 节点 12.18.2
- npm 6.14.6
- nuxt 2.13.3(全局)
- 我还在 Windows 10 上以管理员身份运行 VS Code
我可以使用以下格式运行命令:npx nuxt build &&npx nuxt export
(在nuxt 之前添加npx
),这是一个快速修复,但我想知道我做错了什么.
I can run the commands with this format: npx nuxt build && npx nuxt export
(adding npx
before nuxt), it's a quick fix but I'd like to know what I'm doing wrong.
我尝试了 npm cache clean --force
,删除了所有 node_modules
和 package-lock.json
文件.然后运行 npm install
但没有成功.
I've tried npm cache clean --force
, deleted all node_modules
, and the package-lock.json
file. And after that ran npm install
but to no success.
编辑.16.10.2020
Edit. 16.10.2020
这个问题在其他 npm 包中仍然存在,比如.讨厌.
This issue is still persistent with other npm packages, like. Gridsome.
C:\Users\MYNAME\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found
推荐答案
您无法直接从终端运行 nuxt
命令的原因是 nuxt
包未全局安装,因此您的终端不会知道 nuxt
的存在,尽管它已安装在本地.
The reason you weren't able to run nuxt
commands directly from the terminal is the nuxt
package is not installed globally, therefore your terminal would not know of the existence of nuxt
, despite having it installed locally.
如果您确实想运行 nuxt
命令,您应该做的是从本地 node_modules
目录中指定 nuxt
包路径像这样:
If you do want to run the nuxt
command, what you should do is to specify the nuxt
package path from your local node_modules
directory like so:
./node_modules/nuxt/bin/nuxt.js build # equivalent to npm run build or yarn build
./node_modules/nuxt/bin/nuxt.js start # equivalent to npm run start or yarn start
然而,大多数时候您不想将 Nuxt 安装为全局包,也不想直接运行 nuxt
命令.您可能想要做的是使用 npm
或 yarn
根据您在 scripts"
下指定的内容为您运行 Nuxt 命令package.json
像这样:
However, most of the times you don't want to install Nuxt as a global package, nor you'd want to run the nuxt
commands directly. What you probably want to do is use npm
or yarn
to run the Nuxt commands for you based on what you specify under "scripts"
in package.json
like so:
// package.json
{
"scripts": {
...
"build": "nuxt build",
"start": "nuxt start",
...
}
...
}
对应的命令是:
npm run build && npm run start
或
yarn build && yarn start
这篇关于nuxt:找不到命令 |必须使用 npx 而不是 npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!