为什么在使用 npm install -g package 时会收到 Unexpected token 'u0000' [英] Why am I getting Unexpected token 'u0000' when using npm install -g package

查看:40
本文介绍了为什么在使用 npm install -g package 时会收到 Unexpected token 'u0000'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是 Windows 特定的问题,但我在谷歌搜索此问题时没有找到任何信息.我一直在使用依赖 Cordova(或 Phonegap)的 ionic 框架.但是,问题并非特定于这些软件包中的任何一个.我经常看到这个错误.因此,错误是当我运行如下命令时:

This is probably a Windows specific issue but I haven't found any information when googling this issue. I had been using ionic framework which relies on Cordova (or Phonegap). However, the problem is not specific to any of these packages. I see this error quite often. So, the error is when I run a command such as the following:

npm install -g cordova

但是,我可以替换各种其他包并得到相同的错误.我将粘贴错误消息下方的代码段(非常简短).奇怪的是,我之前有一个 ionic 项目在该目录中工作.然后今天它告诉我找不到离子.我的预感是,这与我在这里描述的主要问题不同.

However, I could substitute various other packages and get the same error. I'll paste the snippet (very brief) below of the error message. What is strange is that I had an ionic project working in that directory earlier. Then today it told me that ionic could not be found. My hunch is that this is a different issue than the main issue I am describing here.

我安装了 git bash,所以我有一个类似 linux 的环境可以尝试.我只想为带有各种 bash 命令的 bash 窗口选择 Git Bash.如果有更简单的方法可以为 Windows 用户解决此问题,请告诉我.我看过有关 Pluralsight 的课程,其中教师似乎很高兴使用 npm 没有任何问题.此外,当我使用 yeoman 时,在很多情况下,我也会在某些时候遇到相同的错误.
错误是

I installed git bash so I do have a linux-like environment that I could try. I would just select Git Bash for a bash window with various bash commands. If there is an easier way to fix this for Windows users, please let me know. I have seen courses on Pluralsight where the instructors seem to be happily using npm with no problems. Also, when I use yeoman, I also at some point, in many cases, get the same error.
The error is

npm ERR! Failed to parse json
npm Unexpected token 'u0000' at 1:1
npm ERR!
npm ERR! ^
npm ERR! File: c:UsersBruceAppDataRoaming
pm-cacheamdefine1.0.0packagepackage.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm
npm ERR! Tell the package author to fix their package.json file. JSON.parse.

预先感谢您的任何帮助/建议,布鲁斯

Thanks in advance for any help/advice, Bruce

推荐答案

通过 关于 SO 的这个问题可能是你必须做的:

Via this question on SO it could be that you just have to do:

npm 缓存清理.

但是,也可以尝试其他建议的方法,例如添加注册表选项:

But, also try the other methods suggested there like adding the registry option:

npm install --registry http://registry.npmjs.org/.

或者,如果您自己一直在使用 package.json 文件,请检查它是否有效.

Or, if you've been mingling with the package.json file by yourself, check if it's valid.

这篇关于为什么在使用 npm install -g package 时会收到 Unexpected token 'u0000'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆