热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

包。一段时间后,json文件被损坏-Thepackage.jsonfilesarecorruptedafterawhile

IuseacorporatecomputerwithWindows10.Ihavenodejsv6.10.0andnpmv3.10.10.Itsthefirstt

I use a corporate computer with Windows 10. I have nodejs v6.10.0 and npm v3.10.10. It's the first time that I install nodejs/npm on this computer.

我使用的是装有Windows 10的公司电脑。我有nodejs v6.10.0和npm v3.10.10。这是我第一次在这台电脑上安装nodejs/npm。

When I install a module (any kind of modules, for example npm install jsdoc) then everything works fine. I can call my example.js several times, and all is OK.

当我安装一个模块(任何类型的模块,例如npm安装jsdoc)时,一切都很正常。我可以举个例子。几次js,一切正常。

But after a while (random period) I cannot run my program anymore because I get the below error:

但是过了一段时间(随机时间),我不能再运行我的程序了,因为我得到了下面的错误:

>node example.js
module.js:96
    throw e;
    ^

SyntaxError: Error parsing C:\my_path\node_modules\some_module\package.json: Unexpected token x in JSON at position 0

If I check the content of the package.json with SublimeText I got:

如果我检查包的内容。json和SublimeText我得到:

78c0 b658 72a3 e0f5 7832 e7d4 b5ee dcc8
8f00 9951 3b8a cbd5 db7f 4556 5e8b e88d
087d 9bb8 ff15 9acb 0a09 7aaf afd3 ced2
3aa9 e2c5 7e7b c4a1 7b82 a332 2848 83ed
adca d7e8 3228 5537 64eb 3105 2338 6ae2
[...]

And actually it's all the package.json files under node_modules for this project that have been corrupted.... For all modules!

实际上它是所有的包。json文件下node_modules对于这个项目已经损坏....所有的模块!

However, if I have a package.json in my project folder, it won't be impacted, only the ones under node_modules folder will be....

但是,如果我有一个包裹。json在我的项目文件夹,它不会受到影响,只会.... node_modules文件夹下的

To fix the issue I have to delete node_modules and reinstall my modules with npm install. Not really handy. After doing it, my package.json files are all correct again with the expected content.

为了解决这个问题,我必须删除node_modules并使用npm安装重新安装模块。不方便的。做完之后,我的包。json文件与预期内容再次一致。

I thought it could be related to our McAfee anti-virus, but why it will only impact the package.json files under node_modules, and not the ones that are in other folders?

我认为它可能与我们的McAfee杀毒软件有关,但为什么它只会影响软件包。node_modules中的json文件,而不是其他文件夹中的json文件?

I read somewhere that a corporate proxy could download a package.json with the wrong encoding, but when I install my modules, the package.json are totally normal.

我在什么地方读到过,公司代理可以下载一个软件包。json编码错误,但当我安装模块时,包。json是完全正常的。

So if anyone has any idea/lead, I'll appreciate!

所以如果有人有任何想法/领导,我会很感激!

EDIT: The corruption stopped to happen since the last release of npm (5.x) ... I don't know if it's related to it, or maybe a Windows update installed, or my I/T dept pushed a software update...

编辑:自从上次npm (5.x)发布以来,这种腐败就不再发生了。我不知道这是否与它有关,或者是安装了Windows update,或者是我的I/T部门推动了软件更新……

3 个解决方案

#1


0  

At this stage, if it was me, I'd be using the SysInternals Process Monitor: Don't assume anything specifically, and just monitor and log all I/O on your system until the files in question start changing. You can set Process Monitor up to record disk actions, and then filter the logs until you see which process is actually changing anything with .json in the name. There will likely be a lot of logs, and you might have to spend a while sifting through them, but it should at least give you something to look at to at least answer the question "What program is changing these files?" instead of having to guess.

在这个阶段,如果是我,我将使用SysInternals Process Monitor:不要特别假设任何东西,只监视并记录系统上的所有I/O,直到有问题的文件开始更改。您可以将Process Monitor设置为记录磁盘操作,然后过滤日志,直到您看到哪个进程在名称中使用.json更改任何内容。可能会有很多日志,您可能需要花一段时间对它们进行筛选,但它至少应该让您有一些东西可以查看,以回答“是什么程序在修改这些文件?”

One other thought: If the files are changing and Process Monitor doesn't show anything at all, you may have a disk that is going bad. Consider doing all your work on a USB drive for a little while and see if the same results happen; if the files are getting corrupted on drive C: but not on drive F: (or whatever), that may suggest your disk is starting to fail. Particularly with SSDs, disks can do some weird things when they start to die.

另一个想法是:如果文件正在更改并且进程监视器没有显示任何内容,那么您的磁盘可能会出现问题。考虑在USB驱动器上完成所有工作一段时间,看看是否会发生同样的结果;如果在驱动器C:而不是驱动器F:(或其他)上的文件被损坏,这可能表明您的磁盘正在开始失败。特别是对于ssd,磁盘在它们开始死亡时可以做一些奇怪的事情。

Tracking these kinds of random file changes can be hard, but there are ways that you can identify the cause; don't give up hope, and you'll find it. Good luck!

跟踪这些随机文件更改可能很难,但是有一些方法可以确定原因;不要放弃希望,你会找到的。好运!

#2


1  

I don't have a specific fix to try, but there are a few general ones that may get you there:

我没有具体的解决办法,但是有一些通用的方法可以帮助你达到目的:

  1. Un-install / Re-install node & npm - Obviously, the first thing you always try if possible.

    卸载/重新安装node & npm——显然,如果可能的话,这是您要做的第一件事。

  2. Turn off all unneeded services / background apps (especially scanners) and see if the problem stops. If so, narrow your scope and turn services on one-by-one while testing. Maybe make a script to run your app enough times that it would normally generate the error.

    关掉所有不需要的服务/后台应用程序(尤其是扫描仪),看看问题是否会停止。如果是这样,缩小范围,在测试时逐个打开服务。也许你可以编写一个脚本,让你的应用程序运行足够多的时间,让它正常地产生错误。

  3. Is there an on-save build tool running? Gulp / Grunt? This could also be the culprit.

    是否有一个正在运行的构建工具?杯/繁重吗?这也可能是罪魁祸首。

I'm guessing if you try the first two suggestions you'll find your problem.

我猜如果你尝试前两个建议,你会发现你的问题。

Also, the read-only thing you mention is odd, but are you sure the proper policies are in place that would allow you to set those permissions? Windows is confusing sometimes as you can change permissions and sometimes it really looks like things went through ok, but they didn't and you really don't notice until things still aren't working and you go back to check the permissions again.

另外,您提到的只读内容是奇怪的,但是您确定适当的策略已经到位,可以允许您设置这些权限吗?Windows有时会让你感到困惑,因为你可以改变权限,有时候看起来好像事情经过了,但是他们没有,你真的没有注意到,直到事情仍然不正常,你再回去检查权限。

#3


0  

This is very strange. The only reason not related to malware than can be causing that would be a problem with encoding. The only valid encodings for JSON are UTF-8, UTF-16 and UTF-32 (both little and big endian) but the safest encoding for package.json is definitely UTF-8 (without BOM).

这是非常奇怪的。唯一与恶意软件无关的原因是编码问题。唯一有效的JSON编码是UTF-8、UTF-16和UTF-32(小的和大的endian),但是对包来说是最安全的编码。json无疑是UTF-8(没有BOM)。

Make sure that you never open it in some editor and save it in anything else than UTF-8.

确保您从未在某些编辑器中打开它,并将它保存在UTF-8之外的任何东西中。

The only other reason for that corruption could be indeed some malware.

造成这种腐败的另一个原因可能是某些恶意软件。

See those answers for more info on JSON and character encoding:

有关JSON和字符编码的更多信息,请参阅这些答案:

  • JSON Specification and usage of BOM/charset-encoding
  • BOM/字符集编码的JSON规范和使用
  • What's different between UTF-8 and UTF-8 without BOM?
  • 没有BOM, UTF-8和UTF-8有什么不同?
  • Node js Syntax error unexpected token?
  • Node js语法错误意外令牌?

If everything is fine after the download, then a possible workaround would be to make every package.json file read-only after the successful installation and see when you will see an error that something cannot write them.

如果下载后一切正常,那么可能的解决方案是制作每个包。json文件在成功安装后是只读的,看看什么时候会出现无法写入的错误。

Another thing I would take a look at is if it happens in every directory or maybe only some directories that you are sharing or syncing or that are on network mounted devices.

另一件我要研究的事情是如果它发生在每个目录或者可能只有一些你正在共享或同步的目录或者网络安装设备上的目录。


推荐阅读
  • 本文介绍了Java工具类库Hutool,该工具包封装了对文件、流、加密解密、转码、正则、线程、XML等JDK方法的封装,并提供了各种Util工具类。同时,还介绍了Hutool的组件,包括动态代理、布隆过滤、缓存、定时任务等功能。该工具包可以简化Java代码,提高开发效率。 ... [详细]
  • 本文介绍了C#中生成随机数的三种方法,并分析了其中存在的问题。首先介绍了使用Random类生成随机数的默认方法,但在高并发情况下可能会出现重复的情况。接着通过循环生成了一系列随机数,进一步突显了这个问题。文章指出,随机数生成在任何编程语言中都是必备的功能,但Random类生成的随机数并不可靠。最后,提出了需要寻找其他可靠的随机数生成方法的建议。 ... [详细]
  • 图解redis的持久化存储机制RDB和AOF的原理和优缺点
    本文通过图解的方式介绍了redis的持久化存储机制RDB和AOF的原理和优缺点。RDB是将redis内存中的数据保存为快照文件,恢复速度较快但不支持拉链式快照。AOF是将操作日志保存到磁盘,实时存储数据但恢复速度较慢。文章详细分析了两种机制的优缺点,帮助读者更好地理解redis的持久化存储策略。 ... [详细]
  • 本文介绍了作者在开发过程中遇到的问题,即播放框架内容安全策略设置不起作用的错误。作者通过使用编译时依赖注入的方式解决了这个问题,并分享了解决方案。文章详细描述了问题的出现情况、错误输出内容以及解决方案的具体步骤。如果你也遇到了类似的问题,本文可能对你有一定的参考价值。 ... [详细]
  • 如何在服务器主机上实现文件共享的方法和工具
    本文介绍了在服务器主机上实现文件共享的方法和工具,包括Linux主机和Windows主机的文件传输方式,Web运维和FTP/SFTP客户端运维两种方式,以及使用WinSCP工具将文件上传至Linux云服务器的操作方法。此外,还介绍了在迁移过程中需要安装迁移Agent并输入目的端服务器所在华为云的AK/SK,以及主机迁移服务会收集的源端服务器信息。 ... [详细]
  • Linux如何安装Mongodb的详细步骤和注意事项
    本文介绍了Linux如何安装Mongodb的详细步骤和注意事项,同时介绍了Mongodb的特点和优势。Mongodb是一个开源的数据库,适用于各种规模的企业和各类应用程序。它具有灵活的数据模式和高性能的数据读写操作,能够提高企业的敏捷性和可扩展性。文章还提供了Mongodb的下载安装包地址。 ... [详细]
  • PDF内容编辑的两种小方法,你知道怎么操作吗?
    本文介绍了两种PDF内容编辑的方法:迅捷PDF编辑器和Adobe Acrobat DC。使用迅捷PDF编辑器,用户可以通过选择需要更改的文字内容并设置字体形式、大小和颜色来编辑PDF文件。而使用Adobe Acrobat DC,则可以通过在软件中点击编辑来编辑PDF文件。PDF文件的编辑可以帮助办公人员进行文件内容的修改和定制。 ... [详细]
  • Oracle优化新常态的五大禁止及其性能隐患
    本文介绍了Oracle优化新常态中的五大禁止措施,包括禁止外键、禁止视图、禁止触发器、禁止存储过程和禁止JOB,并分析了这些禁止措施可能带来的性能隐患。文章还讨论了这些禁止措施在C/S架构和B/S架构中的不同应用情况,并提出了解决方案。 ... [详细]
  • 集成电路企业在进行跨隔离网数据交换时面临着安全性问题,传统的数据交换方式存在安全性堪忧、效率低下等问题。本文以《Ftrans跨网文件安全交换系统》为例,介绍了如何通过丰富的审批流程来满足企业的合规要求,保障数据交换的安全性。 ... [详细]
  • 本文讨论了编写可保护的代码的重要性,包括提高代码的可读性、可调试性和直观性。同时介绍了优化代码的方法,如代码格式化、解释函数和提炼函数等。还提到了一些常见的坏代码味道,如不规范的命名、重复代码、过长的函数和参数列表等。最后,介绍了如何处理数据泥团和进行函数重构,以提高代码质量和可维护性。 ... [详细]
  • 本文详细介绍了cisco路由器IOS损坏时的恢复方法,包括进入ROMMON模式、设置IP地址、子网掩码、默认网关以及使用TFTP服务器传输IOS文件的步骤。 ... [详细]
  • 本文讨论了在VMWARE5.1的虚拟服务器Windows Server 2008R2上安装oracle 10g客户端时出现的问题,并提供了解决方法。错误日志显示了异常访问违例,通过分析日志中的问题帧,找到了解决问题的线索。文章详细介绍了解决方法,帮助读者顺利安装oracle 10g客户端。 ... [详细]
  • 本文介绍了一个免费的asp.net控件,该控件具备数据显示、录入、更新、删除等功能。它比datagrid更易用、更实用,同时具备多种功能,例如属性设置、数据排序、字段类型格式化显示、密码字段支持、图像字段上传和生成缩略图等。此外,它还提供了数据验证、日期选择器、数字选择器等功能,以及防止注入攻击、非本页提交和自动分页技术等安全性和性能优化功能。最后,该控件还支持字段值合计和数据导出功能。总之,该控件功能强大且免费,适用于asp.net开发。 ... [详细]
  • 背景应用安全领域,各类攻击长久以来都危害着互联网上的应用,在web应用安全风险中,各类注入、跨站等攻击仍然占据着较前的位置。WAF(Web应用防火墙)正是为防御和阻断这类攻击而存在 ... [详细]
  • Android自定义控件绘图篇之Paint函数大汇总
    本文介绍了Android自定义控件绘图篇中的Paint函数大汇总,包括重置画笔、设置颜色、设置透明度、设置样式、设置宽度、设置抗锯齿等功能。通过学习这些函数,可以更好地掌握Paint的用法。 ... [详细]
author-avatar
手机用户2502858405
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有