简体   繁体   English

vscode package.json 字符串与模式不匹配

[英]vscode package.json String does not match the pattern

I am trying out VSCode on an existing project that uses npm and has a package.json file with a corresponding "name:" key that reads "SpecPro-File-Management-UI".我正在使用 npm 的现有项目上尝试 VSCode,该项目有一个 package.json 文件,该文件具有相应的“名称:”键,读取“SpecPro-File-Management-UI”。 VSCode is objecting to this line with "String does not match the pattern ...", apparently because of the upper-case characters in the name. VSCode 以“字符串与模式不匹配...”来反对这一行,显然是因为名称中的大写字符。

This problem is described in a VSCode issue which is closed.此问题在已关闭的VSCode 问题中进行了描述。 Which leaves me with advice to setup a custom schema for my package.json file.这给我留下了为我的 package.json 文件设置自定义架构的建议 This is pretty unfriendly, and a barrier to adopting VSCode.这是非常不友好的,也是采用 VSCode 的障碍。 I don't want to spend my time on custom schemas.我不想把时间花在自定义模式上。 I don't want to rename my project.我不想重命名我的项目。 I just want to edit my code and take advantage of the many VSCode goodies without distracting messages that are wrong.我只想编辑我的代码并利用许多 VSCode 好东西,而不会分散错误消息的注意力。

Considering that using uppercase characters for npm packages is a VERY common practice, it seems most reasonable that VSCode should adopt either a more friendly schema or an easy way to override the standard schema.考虑到在 npm 包中使用大写字符是一种非常常见的做法, VSCode 应该采用更友好的模式或覆盖标准模式的简单方法似乎是最合理的。 As far as I can tell, I have to make my own personal schema to resolve this problem.据我所知,我必须制作自己的个人模式来解决这个问题。 That's a lot of work and future maintenance for such a simple issue.对于这样一个简单的问题,这需要大量的工作和未来的维护。

Is there an easy way to banish this erroneous error message?有没有一种简单的方法可以消除这个错误的错误信息?

This behavior is by design to enforce NPM conventions for the package.json file (to paraphrase, "lower-case only").这种行为是为了对 package.json 文件强制执行 NPM 约定而设计的(解释为“仅小写”)。 I agree it is a nuisance, especially since the project name is often pre-filled, eg by "create-react-app".我同意这很麻烦,特别是因为项目名称通常是预先填写的,例如“create-react-app”。 As you point out, it is possible to create a custom schema to ignore this, but it's really not recommended.正如您所指出的,可以创建一个自定义架构来忽略这一点,但确实不建议这样做。 There isn't any alternative at this time.目前没有其他选择。 Myself, I just change the value to lower-case.我自己,我只是将值更改为小写。

使用以连字符(-)分隔的小写名称字段值。

In tsconfig.json add this line or set its value to false.在 tsconfig.json 添加此行或将其值设置为 false。 This worked for me.这对我有用。

"forceConsistentCasingInFileNames": false, // Fix for name regex pattern "forceConsistentCasingInFileNames": false, // 修复名称正则表达式模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM