记录一次vue的启动
以下步骤在管理员权限下执行
安装node.js
网上一堆
idea安装vue.js插件
过于简单
安装vue-cli
npm install -g vue-cli
构建项目(已经有项目忽略这一步)
vue init webpack frontend
安装项目依赖
需要切换到项目根目录下,有个package.json,直接使用npm install
命令就可以识别安装
这一步经常出问题
如果出问题了,不要慌,下面给出我遇到的问题的坑:
需要python2.7
第一次运行出错:
根据提示查看日志文件:
之后在日志文件中发现
3796 error gyp verb check python checking for Python executable "python2" in the PATH
3796 error gyp verb which
failed Error: not found: python2
虽然不知道为什么需要python的上古时代的2.0技术,但是还必须要按照提示安装
http://dragon.feisir.top:5244/d/small/软件/编程/python/python-2.7.2.amd64.msi
点击下载安装即可,选择默认安装路径,这样不会影响python3.0+体系。
使用这条命令将npm指向python2.7
npm config set python python2.7
删除node-moduls重来
使用国内镜像下载
npm set registry https://registry.npm.taobao.org
# 注册模块镜像
npm set disturl https://npm.taobao.org/dist # node-gyp
编译依赖的 node 源码镜像
npm cache clean --force
# 清空缓存
npm install -g cnpm --registry=https://registry.npm.taobao.org
# 安装cnpm
执行cnpm install出现错误
gyp ERR! This is a bug in node-gyp
.
gyp ERR! Try to update node-gyp and file an Issue if it does not help:
gyp ERR! https://github.com/nodejs/node-gyp/issues
Build failed with error code: 7
[npminstall:runscript:error] node-sass@^4.14.1 scripts.postinstall run "node scripts/build.js" error: Error [RunScriptError]: Run "C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js" error, exit code 1
at ChildProcess.
at ChildProcess.emit (node:events:520:28)
at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) {
stdio: [Object],
exitcode: 1
}
× Install fail! RunScriptError: post install error, please remove node_modules before retry!
Run "C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js" error, exit code 1
RunScriptError: Run "C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js" error, exit code 1
at ChildProcess.
at ChildProcess.emit (node:events:520:28)
at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
这个错误给了两个提示(加粗部分)
- 尝试升级node-gyp,如果没有效果的话访问https://github.com/nodejs/node-gyp/issues去寻找解决办法
- 删除node-moduls,再次尝试install
首先试了一下删除node-moduls再次尝试cnpm install
代理问题
出现同样的错误,删除node-moduls尝试npm install
提示不让通过代理下载,设置禁止使用代理
npm config set proxy false
关闭代理,npm cache verify
使缓存生效。
清除node-moduls文件继续。还是失败,同样的错误!!
node-gyp升级
看来只有升级node-gyp了,既然都折腾了这么久,不如了解下node-gyp到底是个啥,引用知乎上的回答
要理解node-gyp首先要知道什么是gyp(https://gyp.gsrc.io/index.md)。gyp其实是一个用来生成项目文件的工具,一开始是设计给chromium项目使用的,后来大家发现比较好用就用到了其他地方。生成项目文件后就可以调用GCC, vsbuild, xcode等编译平台来编译。至于为什么要有node-gyp,是由于node程序中需要调用一些其他语言编写的工具甚至是dll,需要先编译一下,否则就会有跨平台的问题,例如在windows上运行的软件copy到mac上就不能用了,但是如果源码支持,编译一下,在mac上还是可以用的。
所以这样一来就解释清楚了为什么前面需要python了,就是为了编译一些东西,至于为什么是2.0的那就不得而知了
接下来看看提示给出的网页https://github.com/nodejs/node-gyp/issues会给出什么答案:
经过一番寻找,终于找到一个相似的问题https://github.com/nodejs/node-gyp/issues/2366
来看看他遇到的错误
在这里看见了相似的错误,于是当下决定一探究竟
在这里看见了原作者的回答
让升级后再试试,我们按照提示来做
npm install --global --production windows-build-tools
安装windows下各语言的编译工具包(其实一般最新的node.js中有)
npm install -g node-gyp
单独安装node-gpy(用这条命令就可以,不用使用最新版的。)
npm install --global node-gyp@latest
安装最新版node-gpy
最后成功::
运行项目
项目根目录下,使用npm run server
即可
大功告成!!!!