json - npm - 未安装;路径中的非法字符

标签 json node.js visual-studio-2015 npm asp.net-core

从一个早已离去的同事那里继承了一个坏掉的 NLog 项目...

  • VS2015 更新 2
  • 最新 Node 安装
  • 最新的 npm 更新 3.10.3
  • '.net 5.0'项目(pre-core 1.0)

我的 npm Node 总是显示“npm - 未安装”

NPM not installed

当我右键单击时,我立即得到“路径中的非法字符”

enter image description here

这是我的 package.json

{
"version": "0.0.0",
"name": "asp.net",
"devDependencies": {
    "gulp": "^3.9.0",
    "gulp-bower": "^0.0.11",
    "gulp-concat": "^2.6.0",
    "gulp-install": "^0.6.0",
    "gulp-sass": "^2.1.1",
    "gulp-uglify": "^1.5.1",
    "gulp-util": "^3.0.7",
    "gulp-watch": "^4.3.5",
    "run-sequence": "^1.1.5",
    "browser-sync": "^2.10.0",
    "gulp-filter": "^3.0.1",
    "main-bower-files": "^2.9.0",
    "gulp-rename": "^1.2.2",
    "gulp-sourcemaps": "^1.6.0"
}

这是我的 project.json:

{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final",
    "Microsoft.AspNet.Session": "1.0.0-rc1-final",
    "Microsoft.AspNet.SignalR.Server": "3.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.Caching.Memory": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.NLog": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
    "MvcWebApiCors": "0.3.0"
},
"commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
},
"frameworks": {
    "dnx451": {
  "dependencies": {
    "Rally.RestApi": "1.0.0-*"
  }
    }
},
"exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
],
"publishExclude": [
    "node_modules",
    "bower_components",
    "**.kproj",
    "**.user",
    "**.vspscc"
],
"scripts": {
    "postrestore": [ "npm install" ],
    "prepare": [ "gulp" ]
}

这是我的 Bower.json

{
"name": "WebApplication",
"private": true,
"dependencies": {
    "bootstrap": "^4.0.0-alpha.2",
    "signalr": "^2.2.0",
    "font-awesome": "^4.5.0",
    "moment": "^2.11.0",
    "Chart-js": "^1.0.2",
    "tether": "^1.1.1",
    "bootstrap-daterangepicker": "2.1.17",
    "handlebars": "^4.0.5",
    "chosen": "^1.4.2"
}

全局.json

{
"projects": [
"src",
"wrap"
],
"sdk": {
"version": "1.0.0-rc1-update1"
}

总体问题是没有显示任何 css/样式。与我们的 iis 盒子上的内容相比,该网站看起来很简陋。

最佳答案

尝试全局安装 npm 包时遇到同样的问题(使用 -g 标志)。 我尝试全局安装的任何 npm 包都会抛出下面给出的相同错误。

npm ERR! code EINVAL
npm ERR! path C:\Users\xxxxxxx'C:\Users\xxxxxxx\AppData\Roaming\npm
npm ERR! Illegal characters in path.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\xxxxxxx\AppData\Local\npm-cache\_logs\2021-12-15T10_49_39_874Z-debug.log

我检查了 PATH 变量。一切顺利。

在互联网上进行了一些研究后,尝试了以下命令

npm bin -g

这显示了一条奇怪的路径。

C:\Users\xxxxxx'C:\Users\xxxxxx\AppData\Roaming\npm
(not in PATH env variable)

看完this post ,我尝试设置 npm config 的路径前缀,成功了!

我是这样设置的。

npm config set prefix C:\Users\xxxxxxx\AppData\Roaming\npm

您可以检查并确认相同的使用,

npm config get prefix

理想情况下,此路径已添加到我的主目录 (C:\Users\xxxxxxx) 中的“.npmrc”文件中。如果“.npmrc”文件中没有任何其他内容(例如私有(private) npm 注册表的访问 token ),删除该文件将解决此问题。

Just posting here, so that someone facing similar issue might find this helpful as the question title relates to this issue.

关于json - npm - 未安装;路径中的非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38079186/

相关文章:

java - 在groovy中解析JSON时如何保持键的顺序

javascript - 铁路中的 express-subdomain-handler 告诉我子域参数(在 route )是 Controller 为什么?

c# - 如何在 Visual Studio MVC 项目中使用 application Insights REST API

c# - WPF 设计器无法加载 VS2015

php - json_decode 返回 NULL 和有效的 JSON 数据

json - 使用返回 JSON 的动态 SQL 时省略数字列中的科学记数法

node.js - 分析服务到服务 google-auth-library-nodejs

javascript - 多类型用户的 Mongoose 模型

c# - 断点绑定(bind)失败 - Visual Studio 2015

json - 使用 KornShell 解析 JSON 的方法