当前位置: 首页 > 知识库问答 >
问题:

前端 - npm install 安装模板不成功?

司浩壤
2024-07-29

下载了 PanJiaChen/vue-admin-template 的模板,但 npm install 安装不成功(把镜像换成了淘宝的镜像)。
显示:

npm warn deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.  
npm error code 1
npm error path E:\a\vue-admin-template\vue-admin-template\node_modules\node-sass
npm error command failed
npm error command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js
npm error Building: C:\Program Files\nodejs\node.exe E:\a\vue-admin-template\vue-admin-template\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm error gyp info it worked if it ends with ok
npm error gyp verb cli [
npm error gyp verb cli   'C:\\Program Files\\nodejs\\node.exe',
npm error gyp verb cli   'E:\\a\\vue-admin-template\\vue-admin-template\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm error gyp verb cli   'rebuild',
npm error gyp verb cli   '--verbose',
npm error gyp verb cli   '--libsass_ext=',
npm error gyp verb cli   '--libsass_cflags=',
npm error gyp verb cli   '--libsass_ldflags=',
npm error gyp verb cli   '--libsass_library='
npm error gyp verb cli ]
npm error gyp info using node-gyp@3.8.0
npm error gyp info using node@18.17.1 | win32 | x64
npm error gyp verb command rebuild []
npm error gyp verb command clean []
npm error gyp verb clean removing "build" directory
npm error gyp verb command configure []
npm error gyp verb download using dist-url https://npm.taobao.org/dist
npm error gyp verb check python checking for Python executable "python2" in the PATH
npm error gyp verb `which` failed Error: not found: python2
npm error gyp verb `which` failed     at getNotFoundError (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:13:12)
npm error gyp verb `which` failed     at F (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:68:19)
npm error gyp verb `which` failed     at E (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:80:29)
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:89:16
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\isexe\index.js:42:5
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\isexe\windows.js:36:5
npm error gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:210:21)
npm error gyp verb `which` failed  python2 Error: not found: python2
npm error gyp verb `which` failed     at getNotFoundError (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:13:12)
npm error gyp verb `which` failed     at F (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:68:19)
npm error gyp verb `which` failed     at E (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:80:29)
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:89:16
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\isexe\index.js:42:5
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\isexe\windows.js:36:5
npm error gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:210:21) {
npm error gyp verb `which` failed   code: 'ENOENT'
npm error gyp verb `which` failed }
npm error gyp verb check python checking for Python executable "python" in the PATH
npm error gyp verb `which` failed Error: not found: python
npm error gyp verb `which` failed     at getNotFoundError (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:13:12)
npm error gyp verb `which` failed     at F (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:68:19)
npm error gyp verb `which` failed     at E (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:80:29)
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:89:16
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\isexe\index.js:42:5
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\isexe\windows.js:36:5
npm error gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:210:21)
npm error gyp verb `which` failed  python Error: not found: python
npm error gyp verb `which` failed     at getNotFoundError (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:13:12)
npm error gyp verb `which` failed     at F (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:68:19)
npm error gyp verb `which` failed     at E (E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:80:29)
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\which\which.js:89:16
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\isexe\index.js:42:5
npm error gyp verb `which` failed     at E:\a\vue-admin-template\vue-admin-template\node_modules\isexe\windows.js:36:5
npm error gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:210:21) {
npm error gyp verb `which` failed   code: 'ENOENT'
npm error gyp verb `which` failed }
npm error gyp verb could not find "python". checking python launcher
npm error gyp verb could not find "python". guessing location
npm error gyp verb ensuring that file exists: C:\Python27\python.exe
npm error gyp ERR! configure error
npm error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
npm error gyp ERR! stack     at PythonFinder.failNoPython (E:\a\vue-admin-template\vue-admin-template\node_modules\node-gyp\lib\configure.js:484:19)
npm error gyp ERR! stack     at PythonFinder.<anonymous> (E:\a\vue-admin-template\vue-admin-template\node_modules\node-gyp\lib\configure.js:509:16)
npm error gyp ERR! stack     at callback (E:\a\vue-admin-template\vue-admin-template\node_modules\graceful-fs\polyfills.js:306:20)
npm error gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:210:21)
npm error gyp ERR! System Windows_NT 10.0.19045
npm error gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "E:\\a\\vue-admin-template\\vue-admin-template\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" 
"--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm error gyp ERR! cwd E:\a\vue-admin-template\vue-admin-template\node_modules\node-sass
npm error gyp ERR! node -v v18.17.1
npm error gyp ERR! node-gyp -v v3.8.0
npm error gyp ERR! not ok
npm error Build failed with error code: 1
npm error A complete log of this run can be found in: C:\Users\Komorebi\AppData\Local\npm-cache\_logs\2024-07-28T06_16_21_102Z-debug-0.log

共有3个答案

翟奕
2024-07-29

1,npm 安装 node-sass 失败的解决方法, 参考 https://runoops.com/note-npm-node-sass-err.html;
2,python2 没有正确安装;

夔修伟
2024-07-29

看起来是没有成功切换到新的淘宝源(https://registry.npmmirror.com
老的域名 npm.taobao.org 已经在 2024-01-22 过期。

node-sass 在安装过程中安装失败会尝试本地 build,本地编译会需要 py 环境,所以会有遇到OP你贴出来的报错信息:

npm error gyp verb check python checking for Python executable "python2" in the PATH
npm error gyp verb `which` failed Error: not found: python2

切换到新的淘宝源地址就好了。

相关链接

  • 为什么node-sass总是安装失败? - 前端流浪者 - SegmentFault 思否
  • 【望周知】淘宝 NPM 镜像站喊你切换新域名啦 - 知乎
  • 淘宝镜像老域名SSL证书已过期
慎望
2024-07-29

从你提供的错误信息来看,主要问题出在 node-sass 的编译过程中,特别是与 Python 相关的依赖。node-sass 需要 Python(通常是 Python 2.x,但现在更推荐使用 Python 3.x,并且确保版本与 node-gyp 兼容)来编译一些本地模块。此外,core-js 版本过旧也是一个需要注意的问题,但这不是导致 npm install 失败的主要原因。

以下是一些解决步骤:

  1. 更新 Python
    确保你的系统上安装了 Python。由于 Python 2.x 已经不再维护,建议安装 Python 3.x(如 Python 3.7 或更高版本)。安装后,确保 Python 的可执行文件路径被添加到了系统的环境变量 PATH 中。
  2. 安装或更新 node-gyp
    node-gyp 是一个用于编译原生 Node.js 模块的跨平台工具。你可以通过 npm 安装或更新它:

    npm install -g node-gyp
  3. 全局安装 Windows 构建工具
    如果你使用的是 Windows,并且 npm 报告缺少编译工具,你可能需要安装 Windows 构建工具。这可以通过运行以下命令来安装(可能需要管理员权限):

    npm install --global --production windows-build-tools
  4. 考虑替换 node-sass
    由于 node-sass 依赖于 Node.js 的原生模块编译,这可能导致跨平台兼容性问题。考虑将 node-sass 替换为 sassdart-sass,它们通常更稳定且易于安装:

    npm uninstall node-sass
    npm install sass --save-dev

    然后你可能需要在你的项目中修改引用 node-sass 的部分以使用 sass

  5. 清理 npm 缓存
    有时候,清理 npm 的缓存可以解决一些奇怪的安装问题:

    npm cache clean --force
  6. 重新运行 npm install
    在进行了上述更改后,尝试再次运行 npm install
  7. 检查 npm 日志
    如果问题仍然存在,检查 npm 日志文件(如你提供的路径中的 2024-07-28T06_16_21_102Z-debug-0.log)可能会提供更多关于错误原因的线索。

通过这些步骤,你应该能够解决 npm install 过程中的问题。如果问题仍然存在,可能需要更详细地检查项目的依赖和配置。

 类似资料:
  • 模板安装、修改: 该文档正在编写中...

  • 环境准备 请参考环境准备 创建工作目录 export HOME=/home/work export WORKSPACE=$HOME/open-falcon mkdir -p $WORKSPACE cd $WORKSPACE 克隆前端组件代码 cd $WORKSPACE git clone https://github.com/open-falcon/dashboard.git 安装依赖包 yu

  • 当我尝试部署Yii2高级模板时,我总是会遇到一个无法工作的应用程序。 错误消息是: 无效参数–yii\base\InvalidParamException要发布的文件或目录不存在:[……]/yii应用程序/供应商/鲍尔/jquery/dist 我尝试通过最新的composer版本进行安装,无论是否使用fxp资产插件。两种情况下的错误消息相同。 我使用官方文档在我的Ubuntu64 16.04 We

  • 使用 Handlebars 预编译器,你可以预编译 Handlebars 模板以节省客户端时间并减少 Handlebars 库所需的运行时大小。 入门 首先,你需要 Node.js 和 npm 。转到 https://nodejs.org/en/download/ 了解如何在你的操 作系统上执行此操作。 接下来,安装 Handlebars npm 软件包,其中包含了预编译器。 npm instal

  • 环境准备 请参考环境准备 创建工作目录 export HOME=/home/work export WORKSPACE=$HOME/open-falcon mkdir -p $WORKSPACE cd $WORKSPACE 克隆前端组件代码 cd $WORKSPACE git clone https://github.com/open-falcon/dashboard.git 安装依赖包 yu

  • npminstall Make npm install fast and handy. Use as Cli Install $ npm install npminstall -g Usage In cnpm It is integrated in cnpm. $ npm install cnpm -g$ cnpm install // will use npminstall npminstal