Mac环境下执行npm init nuxt-app无法创建Nuxt项目求助
Nuxt项目创建报错(Error Code 127)解决办法
环境信息
- 系统:Mac (Darwin 23.2.0)
- Node.js版本:v20.11.0
- NPM版本:v10.2.4
- @vue/cli版本:5.0.8(可正常创建并运行Vue项目)
问题描述
执行npm init nuxt-app nuxt-hello-world命令创建Nuxt项目时,流程执行到第30行后报错,报错信息如下:
31 silly logfile start cleaning logs, removing 1 files 32 timing arborist:ctor Completed in 0ms 33 silly logfile done cleaning log files 34 http fetch GET 200 https://registry.npmjs.org/create-nuxt-app 149ms (cache revalidated) 35 timing arborist:ctor Completed in 0ms 36 timing command:init Completed in 249ms 37 verbose stack Error: command failed 37 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:53:27) 37 verbose stack at ChildProcess.emit (node:events:518:28) 37 verbose stack at maybeClose (node:internal/child_process:1105:16) 37 verbose stack at ChildProcess._handle.onexit (node:internal/child_process:305:5) 38 verbose cwd /Volumes/My Passport 1/myusername/mydirect 39 verbose Darwin 23.2.0 40 verbose node v20.11.0 41 verbose npm v10.2.4 42 error code 127 43 error path /Volumes/My Passport 1//myusername/mydirect 44 error command failed 45 error command sh -c create-nuxt-app nuxt-hello-world 46 verbose exit 127 47 timing npm Completed in 333ms 48 verbose code 127
解决办法
全局安装create-nuxt-app后执行
先全局安装创建工具,再直接运行创建命令:npm install -g create-nuxt-app create-nuxt-app nuxt-hello-world规避路径空格问题
当前工作目录路径包含空格(/Volumes/My Passport 1/...),可能导致Shell解析命令出错。建议切换到无空格的本地目录(如~/projects),再执行创建命令。清理NPM缓存后重试
清理缓存避免缓存损坏导致的问题:npm cache clean --force npm init nuxt-app nuxt-hello-world使用npx直接执行最新版本
用npx直接拉取最新版create-nuxt-app执行,绕过全局安装和版本兼容问题:npx create-nuxt-app@latest nuxt-hello-world
内容的提问来源于stack exchange,提问作者dhiman
相关产品推荐
相关产品推荐

