vue开发错误解决方案集合

Unexpected end of JSON input while parsing near '...nterpret","version":"'

  • 解决步骤
  • This solved it for me

npm cache clean --force

  • then run

npm install -g @angular/cli@latest

  • 参考

https://stackoverflow.com/questions/47675478/npm-install-errorunexpected-end-of-json-input-while-parsing-near-nt-webpack

Module build failed: Error: Couldn't find preset "es2015" relative to direct

  • 执行一下两个命令

    npm install --save-dev babel-cli
    npm install --save-dev babel-preset-es2015

  • 然后就可以启动了

npm 报错:npm ERR! Maximum call stack size exceeded 超过最大栈问题解决方案

错误的原因,npm版本问题;

解决办法:

      1》更新到最新版本:npm install npm -g 要记住全局更新

   2》回退版本:npm install -g npm@5.4.0

npm install 时出现的 EACCES: permission denied

报错原因
在 Linux 系统中,root 用户并不会自动获得 npm 包的安装权限,需要手动设置权限

解决办法
可以通过在执行 npm 命令时添加 --unsafe-perm=true 参数来解决该问题。该参数会告诉 npm 在安装包的过程中不要检查权限,直接以 root 用户身份执行。

npm i --unsafe-perm=true
1
注意
使用 --unsafe-perm=true 参数会使 npm 以 root 用户身份执行,这可能会对系统造成潜在的安全风险。因此,建议仅在必要时使用该参数。

跨域

// vue.config.js文件
module.exports = {
//.....
  devServer: {
    host: 'localhost',
    port: 8080,
    proxy: {
      "/api": {
        target: "http://www.xxx.com", // 请求到/api/xx 就会被代理http://www.xxx.com/api/xxx
        //  secure: false, // 如果是https接口,需要配置这个参数
        changeOrigin: true, // 接口跨域 需打开这个参数
        pathRewrite: {
          '^/api': '', // 忽略前缀/api  则会被代理到http://www.xxx.com/xxx
        },
      }
    }
  },
}

npm code CERT_HAS_EXPIRED

临时忽略SSL证书验证
作为临时解决方案,你可以通过设置npm配置来忽略SSL证书验证。请注意,这种方法会降低安全性,不推荐作为长期解决方案。
npm config set strict-ssl false

安装完所需的包后,最好将此设置还原,以保持更高的安全性:
npm config set strict-ssl true

node install 错误

05:25 Unable to save binary /home/.jenkins/workspace/front-uat-hn-report/node_modules/node-sass/vendor/linux-x64-83 : Error: EACCES: permission denied, mkdir '/home/.jenkins/workspace/front-uat-hn-report/node_modules/node-sass/vendor'

解决办法:
添加--unsafe-perm 参数,如

  • npm install --unsafe-perm 或 npm install --unsafe-perm=true --allow-root

或者再来个淘宝镜像

说明:npm会有生命周期,某个包会有生命周期来执行一些东西,安全起见会自动降级导致没有权限执行一些操作,通过--unsafe-perm参数来解锁该限制。

一劳永逸的方法:

  • npm config set unsafe-perm(针对当前用户的)
  • npm config -g set unsafe-perm(全局的)
  • npm install --unsafe-perm=true --allow-root

将后边加上以上参数完美解决!

参考https://www.jianshu.com/p/b3eb0c11dfd0

node-sass 缺失

16:09:19 Found bindings for the following environments:
16:09:19   - Linux 64-bit with Node.js 14.x
16:09:19 
16:09:19 This usually happens because your environment has changed since running `npm install`.
16:09:19 Run `npm rebuild node-sass` to download the binding for your current environment.
  • 执行 npm rebuild node-sass
posted @ 2025-04-09 11:09  程序员の奇妙冒险  阅读(58)  评论(0)    收藏  举报