Json npm安装后打字不正常

Json npm安装后打字不正常,json,node.js,npm,angular,npm-install,Json,Node.js,Npm,Angular,Npm Install,我有以下packages.json: { "name": "shopping-assistant-angular", "version": "1.0.0", "scripts": { "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ", "tsc": "tsc", "tsc:w": "tsc -w", "lite": "lite-server", "typings": "typings

我有以下packages.json:

{
"name": "shopping-assistant-angular",
"version": "1.0.0",
"scripts": {
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ",    
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "typings": "typings",
    "postinstall": "typings install" 
},
"license": "ISC",
"dependencies": {
    "angular2": "2.0.0-beta.7",
    "systemjs": "0.19.23",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "zone.js": "0.5.14"
},
"devDependencies": {
    "bower": "^1.7.7",
    "concurrently": "^1.0.0",
    "grunt": "^0.4.5",
    "grunt-chrome-manifest": "^0.3.0",
    "grunt-contrib-clean": "^1.0.0",
    "grunt-contrib-concat": "^0.5.1",
    "grunt-contrib-copy": "^0.8.2",
    "grunt-contrib-cssmin": "^0.14.0",
    "grunt-contrib-htmlmin": "^0.6.0",
    "grunt-contrib-uglify": "^0.11.1",
    "grunt-filerev": "^2.3.1",
    "grunt-ts": "^5.3.2",
    "grunt-usemin": "^3.1.1",
    "lite-server": "^2.0.1",
    "load-grunt-tasks": "^3.4.0",
    "typescript": "1.7.5",
    "typings": "^0.6.8"
}
}
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ",    
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "typings": "typings",
    "postinstall": "typings install" 
},
"license": "ISC",
"dependencies": {
    "angular2": "2.0.0-beta.7",
    "systemjs": "0.19.22",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "zone.js": "0.5.15"
},
"devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.1.0",
    "typescript": "^1.7.5",
    "typings":"^0.6.8"
}
}
在我的目录中运行npm install时,我收到一个错误:
“typings”未被识别为内部或外部命令、可操作程序或批处理文件。

在Angular 2快速入门指南中,他们使用以下packages.json:

{
"name": "shopping-assistant-angular",
"version": "1.0.0",
"scripts": {
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ",    
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "typings": "typings",
    "postinstall": "typings install" 
},
"license": "ISC",
"dependencies": {
    "angular2": "2.0.0-beta.7",
    "systemjs": "0.19.23",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "zone.js": "0.5.14"
},
"devDependencies": {
    "bower": "^1.7.7",
    "concurrently": "^1.0.0",
    "grunt": "^0.4.5",
    "grunt-chrome-manifest": "^0.3.0",
    "grunt-contrib-clean": "^1.0.0",
    "grunt-contrib-concat": "^0.5.1",
    "grunt-contrib-copy": "^0.8.2",
    "grunt-contrib-cssmin": "^0.14.0",
    "grunt-contrib-htmlmin": "^0.6.0",
    "grunt-contrib-uglify": "^0.11.1",
    "grunt-filerev": "^2.3.1",
    "grunt-ts": "^5.3.2",
    "grunt-usemin": "^3.1.1",
    "lite-server": "^2.0.1",
    "load-grunt-tasks": "^3.4.0",
    "typescript": "1.7.5",
    "typings": "^0.6.8"
}
}
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ",    
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "typings": "typings",
    "postinstall": "typings install" 
},
"license": "ISC",
"dependencies": {
    "angular2": "2.0.0-beta.7",
    "systemjs": "0.19.22",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "zone.js": "0.5.15"
},
"devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.1.0",
    "typescript": "^1.7.5",
    "typings":"^0.6.8"
}
}
在所有软件包安装完成后,成功运行“typings install”


不确定为什么运行这些非常相似的packages.json文件会导致完全不同的结果。

我也面临同样的问题。您需要在项目文件夹中添加typings.json文件。请检查此链接:

正确(请参阅),首先尝试在全球范围内安装打字
npm install typings-g
如果您使用的是mac,您可能需要使用sudo命令
sudo npm install typings-g

Oh Em-Gee。这个工具太易碎了

PowerShell ->
  OS %PATH% spec ->
    Node.js bin folder (which one?) ->
      typings.cmd ->
        Tools : Options : Projects and Solutions : External Web Tools ->
          node.js bin ->
            Typings JavaScript files ->
              PowerShell working directory (vs. project path) ->
                typings.json configuration ->
请注意,
npm install typings-g
是一个“全局”安装,因此即使您希望它成为单个项目的一部分(例如,您希望能够签出并构建单个项目),也太糟糕了!您必须使用解决方案范围的
package.json
文件签出解决方案,才能获得项目工具链

请注意,默认的Typings安装会修改Node.js binaries文件夹。因此,如果您有多个Node.js安装(您可能至少有三个,一个是用VS update 2安装的,至少一个是用NuGet安装的,一个或多个是作为单独的Node.js安装的,以克服其他两个源提供的旧版本中的缺陷),那么您的痛苦已经开始了

此外,您的一些开发团队根据各种MS支持文章修改了他们的外部Web工具目录以解决此问题,并且您的团队的一些成员安装了不同的Node.js版本,等等。现在您的痛苦变得现实了

那么,解决方案是什么?就我个人而言,我将在gulp.js“项目启动时运行”事件中插入“typings install”,并将其设置为针对特定项目的“typings”包。现在我们可以签出并构建单个项目,团队中没有人需要能够在命令行或包管理器控制台上运行“typings install”,只有一个人负责维护它

这些路径也可能对您有所帮助。在机器升级期间的不同时间点,我在上执行了大部分诊断,
npm install typings-g
在不同的目录中放置了一个
typings.cmd
文件:

  • %SolutionFolder%\packages\Node.js.5.3.0\typings.cmd
  • C:\Users\%username%\AppData\Roaming\npm\typings.cmd

您不需要全局安装打字机,上述设置才能正常工作。运行
npm install
时,应在
/node\u modules/.bin/typings
处添加到typings二进制文件的符号链接,并且应在PATH环境变量中添加
/node\u modules/.bin
的情况下运行postinstall脚本


但是,看看您的设置,如果要使用
npm install--production
(或者将
NODE_ENV
环境变量设置为
production
)进行安装,则不会像在
devDependencies
中那样安装打字,因此会出现错误。这可能是你问题的真正原因。看看如何解决这个问题的一些建议。

我倾向于使用嵌套的angular 1和angular 2解决方案,最终存储在Git repos中

当我运行这个命令时,输入的内容没有显示出来

npm run typings install
那是行不通的。然后我找到这个stackoverflow页面并尝试

npm install typings -g
对我来说,问题是在一个作业中,我继承了一个
.typingsrc
文件,即使它不在我正在运行的
npm install
等文件夹中。。在中,它一定决定查找上面的一个或两个目录,因此难怪我会出错

我只是简单地将它重命名为
old.typingsrc
,因为其中的目的是绕过代理
proxy=”http://proxy-chain.company.com:911“


这可能不会帮助很多人,但我认为它可能会帮助那些有代理权的人

在《离子2》中,我在第10窗口遇到了同样的问题,然后我尝试了 npm安装打字-g, 安装后,我尝试了打字命令,哇,它成功了, 我正在使用带socket.io的离子2,我需要运行
打字安装dt~socket.io-client--save--global
, 现在它正在工作


希望这能对您有所帮助。

实际上我的文件夹中有一个typings.json文件,这是因为我没有全局安装typings
npm install typings-g
修复了我的问题始终检查文件名。。。我不小心把我的名字改为typings.json而不是typings.json。这有帮助!我应该回答我自己的问题。感谢angular.io教程曾经提到运行npm install typings-g,但是现在由于他们新的package.json文件的设置方式,它不再是必需的了。您是否能够理解为什么这些package.json中的一个可以工作而另一个不能工作?如果
节点_ENV
环境变量设置为
生产
,也可以导致生成
--production
类型。(我已将其编辑到我的答案中)您好,请在代码中添加一些格式。请查看以了解更多信息。