npm安装心得(依赖库Python及node-sass依赖环境)

news/2024/7/24 5:13:22 标签: 开发语言, 后端, vue.js, node.js, python, 前端

在使用vue的开发环境过程中,总会遇到这样哪样的安装或者打包错误,

vue运行或打包常见错误如下:
1. npm install时 node-sass npm ERR command failed (可能是node.js的版本和node-sass的版本不符,就是卸掉原来的node.js,下载一个符合node-sass版本的node.js
2. npm run build无法打包的可能原因 npm ERR! missing script: build  (package.json中scripts参数为"build:prod": "vue-cli-service build",所以换命令打包:npm rum build:prod)
3. npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11.  (据自己的node版本来更新npm 版本npm -g install npm@6.14.8 ,如果仍然报错,依旧显示npm 不支持这个版本 ,这说明npm存在旧的npm缓存,还是旧的npm 环境
此时需要到C:\Users\administrator\AppData\Roaming 根目录下删除npm和npm-cache两个文件夹)

4. npm install时 node-sass npm ERR command failed问题解决 (卸载当前版本的node-sass和sass-loader,因为版本和当前的不兼容,安装对应版本的包即可。)
5. Syntax Error: Error: PostCSS received undefined instead of CSS string (卸载当前版本的node-sass和sass-loader,因为版本和当前的不兼容,安装对应版本的包即可。)
6. npm ERR! gyp ERR! find Python Python is not set from command line or npm con 
7. npm ERR! gyp verb check python checking for Python executable "python2" in the PATH  (通过npm指令安装对应版本的python(建议方式): npm install --global --production windows-build-tools)
8. npm install时报错 gyp ERR! stack Error: Can't find Python executable "2.7"  (通过npm指令安装对应版本的python(建议方式): npm install --global --production windows-build-tools)
9.使用npm下载直接卡死,超简单解决办法(放大缩小cmd命令窗口或者ctrl+c可中断错误,继续重试脚本)


在install这些框架时,往往还需要安装其要求的依赖,或是相关的编译环境,下面将记录描述下python和node-sass的安装办法:

一:python安装:
1.官网下载安装包,传统安装,然后配置相关环境变量

2.在安装了node但是为安装python的前提下,通过npm指令安装对应版本的python(建议方式):

    npm install --global --production windows-build-tools   (会自动安装对应python)


对于非python玩家,建议方式二安装python环境,该方式,node会为你匹配对应node版本的python,这样将避免后续使用中的版本过高或过低造成的编译失败问题,比如node16+在python2.x下编译会抛出version问题。

二:node-sass安装
node-sass的安装有很多方式,在此我仅介绍一种(多次尝试,这种方式最方便稳定)

node 8.x 以上的小伙伴看这里:

npm install --save node-sass --registry=https://registry.npm.taobao.org --disturl=https://npm.taobao.org/dist --sass-binary-site=https://npm.taobao.org/mirrors/node-sass/ 

//设置全局镜像源:
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/

npm config set registry=https://registry.npm.taobao.org  


–registry=https://registry.npm.taobao.org 淘宝npm包镜像
–disturl=https://npm.taobao.org/dist 淘宝node源码镜像,一些二进制包编译时用
–sass-binary-site=http://npm.taobao.org/mirrors/node-sass 这个才是node-sass镜像

node 8.x 以下的小伙伴看这里:

1.先全局安装cnpm

npm install -g cnpm --registry=https://registry.npm.taobao.org


2.利用淘宝的npm镜像安装node-sass

cnpm install node-sass


CNPM 是中国 npm 镜像的客户端。
-----------------------------------------------------------------
安装
$ npm install cnpm -g

国内安装 China mirror:
$ npm install cnpm -g --registry=https://registry.npm.taobao.org

支持所有 npm命令

构建私有 npm: $ npm install cnpm -g

首先要安装nodejs环境:
---------------------------------------------------------------------
在NodeJS官网(https://nodejs.org/)下载安装合适的版本

https://nodejs.org/dist/v14.17.1/  node-v14.17.1 对应npm版本 6.14.13(依赖python2.7x) 

https://nodejs.org/dist/v16.9.1/   node-v16.9.1 对应npm版本 8.19.2(依赖python3.8x)

https://nodejs.org/dist/v18.17.1/  (太新了,不推荐) 

npm常见命令:
---------------------------------------------------------------------
npm insall  (安装失败的话,删除目录下的node_modules文件夹)

npm run dev  

npm rum serve

npm uninstall -g @vue/cli  安装打包命令cli

npm install -g @vue/cli

npm list webpack  查看包 


npm cache clean --force  清理缓存 

npm start

npm run dev:只是用来调试的,开发就够了;

补充说明:
有一个相似的命令就是下面这个,也是用来搭建环境的,但有一点小区别,具体情况具体额分析。
npm run build:你想用提交小程序版本的时候,运行,然后代码都会被压缩,提交的时候就更小了。
 

gyp ERR stack Error: Can ‘t find Python executable python2.7, you can set the PYTHON env variable.


在公司部署前端项目的时候,npm install 安装依赖的时候出现了问题,发现是node-sass这个包下载失败

在这里插入图片描述在这里插入图片描述

我在想是不是没安装什么呢,因为我是面向百度编程的,所以就百度了一下,发现需要安装编译环境

npm install -g node-gyp 
npm install --global --production windows-build-tools     (这条命令需管理员运行)


然后卸载安装失败的包

npm uninstall node-sass

然后重新安装

npm install node-sass

最后npm install , npm run dev 直接运行就好了。

 If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the '--python' variable:

node-gyp --python /path/to/python2.7
If node-gyp is called by way of npm and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value:

npm config set python /path/to/executable/python2.7
Note that OS X is just a flavour of Unix and so needs python, make, and C/C++. An easy way to obtain these is to install XCode from Apple, and then use it to install the command line tools (under Preferences -> Downloads). 

1、下载安装Python2.7,设置环境变量 : 
npm config set python "D:\python27"


http://www.niftyadmin.cn/n/5040486.html

相关文章

迷宫寻路:(深搜广搜)

迷宫寻路 题目描述 机器猫被困在一个矩形迷宫里。 迷宫可以视为一个 n m n\times m nm 矩阵,每个位置要么是空地,要么是墙。机器猫只能从一个空地走到其上、下、左、右的空地。 机器猫初始时位于 ( 1 , 1 ) (1, 1) (1,1) 的位置,问能否…

zabbix学习1--zabbix6.x单机

文章目录 1. 环境2. MYSQL8.02.1 单节点2.2 配置主从 3. 依赖组件4. zabbix-server5. agent5.1 yum5.2 编译 附录my.cnfJDK默认端口号 1. 环境 进入官网查看所需部署环境配置以及应用版本要求https://www.zabbix.com/documentation/current/zh/manual/installation/requiremen…

【漏洞复现】广联达OA漏洞合集(信息泄露+SQL注入+文件上传)

文章目录 声明广联达OA存在信息泄露一、漏洞概述二、漏洞复现三、修复建议广联达Linkworks办公OA SQL注入漏洞后台文件上传漏洞一、产品简介二、漏洞概述三、复现环境四、修复建议 声明 请勿利用文章内的相关技术从事非法测试,由于传播、利用此文所提供的信息或者工…

iterm2 配置自动登录跳板机,无需输入密码和google验证码

1、准备:编写Python脚本计算生成google身份验证码,参考python3 实现 google authenticator 认证/校验_我要买GTR45的博客-CSDN博客 脚本拿来就可以用,只需要替换脚本中的secret字段的值为自己的密钥即可 2、在~/.ssh/目录下编写expect脚本 …

Continuous embedding

https://www.detailedpedia.com/wiki-Continuous_embedding

C++ Const

常量表达式 常量表达式是指值不会改变并且在编译过程中就能得到计算结果的表达式 // sz不是一个常量表达式,尽管sz本身是一个常量,但它的具体值知道运行时才能获取 const int sz get_size()constexpr变量 声明一个常量表达式 顶层const 顶层const表…

【人工智能】企业如何使用 AI与人工智能的定义、研究价值、发展阶段的深刻讨论

前言 人工智能(Artificial Intelligence),英文缩写为AI。 它是研究、开发用于模拟、延伸和扩展人的智能的理论、方法、技术及应用系统的一门新的技术科学。人工智能是新一轮科技革命和产业变革的重要驱动力量。 📕作者简介&#x…

记录--ipc升级模块流程

一、设置fpt服务器 二、查找本地升级包路径并通过ftp服务器链接引用该路径 三、验证客户账号密码,确认客户信息 四、检查并解析升级包数据,确定要升级的模块,生成令牌并将升级数据写入内存 五、创建下载线程,下载升级包到ipc …