vuejs中运行时碰到的问题

    科技2025-02-10  14

    文章目录

    1 Vuejs报错1.1 npm install 报错1.1.1 npm ERR! Unexpected end of JSON input while parsing near '...sh_time1.1.1.1 报错信息1.1.1.2 解决方案 1.1.2 Error: EPERM: operation not permitted, unlink...1.1.2.1 报错信息1.1.2.2 解决方案1.1.2.2.1 删除node_modules1.1.2.2.2 删除npm缓存 1.2 运行报错1.2.1 Module build failed: Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime1.2.1.1 报错信息1.2.1.2 解决方案1.2.1.2.1 设置源头1.2.1.2.2 重装sass

    1 Vuejs报错

    1.1 npm install 报错

    1.1.1 npm ERR! Unexpected end of JSON input while parsing near '…sh_time

    1.1.1.1 报错信息

    执行npm install的时候报错npm ERR! Unexpected end of JSON input while parsing near '...sh_time":141072930277'.如下图:

    1.1.1.2 解决方案

    直接执行npm cache clean --force, 如果执行成功,再npm install即可。如果执行失败,请先升级npm,即npm i -g npm, 最后再执行npm cache clean --force, 最后再npm install.如果还执行失败,那就先npm cache verify(重新计算缓存文件夹下的文件是否与sha1值匹配),再npm cache clean --force,最后再npm install如果还是执行失败,那就往复的执行 【先npm cache clean --force再npm install】,一直到npm cache clean --force执行成功即可,然后npm install即成功

    如果 npm cache clean --force 执行成功会提示:npm WARN using --force I sure hope you know what you are doing. 如下图:

    1.1.2 Error: EPERM: operation not permitted, unlink…

    1.1.2.1 报错信息

    由于国内外环境因素,npm install安装依赖的时候经常会出现各种问题,特别是Error: EPERM: operation not permitted, unlink…这个错误 这个错误因为报错信息的误导性,导致很多网上提出的解决办法都是什么设置权限,以管理员身份进入等乱七八糟的。 但是用了管理员身份进入后,仍然报错,说明不是权限问题

    其实这个错误出现的原因就是网络不稳定,导致npm包下载不完整或者出错导致的。什么,你家里100M光纤网速飞起?但服务器是国外的,该慢的时候还是得慢。 而一次出错之后,一般人都会再次npm install ,而npm install命令并不会主动清除上次安装的包,而上次安装的包又不完整,包与包之间又有依赖关系,结果自然就会出错。

    所以,要想解决这个问题,就应该清除上次安装的包,想要彻底清除则一般需要以下2步:

    删除node modules中的全部文件清除Npm缓存

    1.1.2.2 解决方案

    1.1.2.2.1 删除node_modules

    删除node_modules文的方式有两种:

    直接右键删除,缺点是依赖过多时,删除速度非常慢。通过安装rimraf来删除【强烈推荐此种方法,光速】。

    安装rimraf(建议全局安装):

    npm install -g rimraf

    使用时,首先进入当前项目的node_modules所在的文件夹。然后直接输入:rimraf node_modules

    1.1.2.2.2 删除npm缓存

    清除Npm缓存的方式有两种:

    直接删除缓存文件,删除C:\Users\用户名.npmrc这个文件。执行:npm cache clean --force,同样达到清除缓存文件的目的

    1.2 运行报错

    1.2.1 Module build failed: Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime

    1.2.1.1 报错信息

    这个错误信息是在npm install后npm run dev时报错的 Module build failed: Error: Cannot find module 'node-sass':找不到node-sass

    npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.14.1 postinstall: `node scripts/build.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node-sass@4.14.1 postinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    1.2.1.2 解决方案

    找不到sass,查看node-sass文件,看里面有没有文件若有,就卸载了重新装,没有就设置sass源,在重新装

    1.2.1.2.1 设置源头

    npm install前设置sass源:

    npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass

    然后在打包npm install,在运行项目npm run dev

    1.2.1.2.2 重装sass
    npm uninstall node-sass npm install node-sass

    然后在打包npm install,在运行项目npm run dev

    Processed: 0.013, SQL: 8