Vue——代码调试遇到的一些错误和解决方案

743 阅读2分钟

1. eslint语法限制项目报错解决办法

问题

image.png

解决方案

如果不想受到eslint语法限制,可以在build/webpack.base.conf.js文件中,注释或者删除掉:module->rules中有关eslint的规则: image.png :要学会适应eslint语法限制,写出整洁的代码!

2. Codesanbox找不打fork?

编辑了一下,保存之后就自动跑到了自己的工作台。

3. 'NODE_ENV' 不是内部或外部命令,也不是可运行的程序或批处理文件。

解决方案

安装across-env:

npm install cross-env –save-dev

在运行命令加前缀:在NODE_ENV=xxxxxxx前面添加cross-env就可以了。

4. vue-cli · Failed to download repo vuejs-templates/webpack: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:1181

问题

image.png 似乎和VPN有关

解决方案

npm config ls -l

image.png

删除https-proxyproxy这两个协议。首先要关掉VPN!!!

npm config delete https-proxy
npm config delete proxy

!!!如果http-proxy不为空也可以delete http-proxy
再次npm config ls -l

image.png 参考juejin.cn/post/688782…

5. TypeErrotr: this.getOption is not a function ar Object.stylusLoader

问题

image.png

解决方案

stylus-loader安装的版本过高,版本降级:

cnpm uninstall stylus-loader
cnpm i stylus-loader@3.0.2 -S

6.

问题

image.png

解决方案

7. vue-cli · Failed to download repo vuejs-templates/vue: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:1181

问题

image.png npm代理问题

解决

npm config set proxy null    
npm config set https-proxy null

常用npm代理操作

  • 查看当前代理
    npm config get proxy
    npm config get https-proxy
    
  • 设置代理
    npm config set proxy http://server:port
    
    npm config set https-proxy http://server:port
    
  • 删除代理
    npm config set proxy null
    npm config set https-proxy null
    
    注:若是遇到git clone Proxy CONNECT aborted的问题也要考虑删除代理 www.jianshu.com/p/a0a953650…

8. vue-cli · Failed to download repo vuejs-templates/vue: unable to verify the first certificate

  • 方案1:电脑上安装了相关用到了代理的软件或者服务,比如一些远程工具,或者一些加速器之类的; 关掉软件或者把服务清理掉。
  • else 方案2:
    npm config set npm_config_strict_ssl=false
    

===================2021.12.26第二次更新==============================

9. Module build failed: TypeError: this.getOptions is not a function at Object.loader

添加如下代码后报错

<style lang="stylus">
</style>

image.png 这个异常说明了当前 style-loader 的版本过高导致 webpack 的编译错误,需要降低版本

解决方法:降低当前style-loader版本

npm install style-loader@<version> --save-dev

如下:

npm install style-loader@1.0.0 --save-dev