简体   繁体   English

在Typescript中使用prettyjson时出错

[英]Error using prettyjson with Typescript

I'm trying to use https://www.npmjs.com/package/prettyjson with Typescript but it can't find the module. 我正在尝试将https://www.npmjs.com/package/prettyjson与Typescript一起使用,但找不到该模块。

I started with package.json: 我从package.json开始:

{
  "name": "prettyjson-test",
  "description": "prettyjson with typescript",
  "private": true,
  "version": "0.0.1",
  "engines": {
    "node": "5.2.x",
    "npm": "3.3.x"
  }
}

Then I ran npm install prettyjson --save 然后我运行npm install prettyjson --save

Next I ran tsd install prettyjson --save 接下来我运行tsd install prettyjson --save

I created pj.ts: 我创建了pj.ts:

/// <reference path="./typings/tsd.d.ts"/>
import prettyjson = require('prettyjson');

Finally, I ran tsc pj.ts --module "commonjs" 最后,我运行了tsc pj.ts --module "commonjs"

C:\\projects\\pj\\pj.ts(3,1): error TS2071: Unable to resolve external module ''prettyjson''. C:\\ projects \\ pj \\ pj.ts(3,1):错误TS2071:无法解析外部模块``prettyjson''。 C:\\projects\\pj\\pj.ts(3,1): error TS2072: Module cannot be aliased to a non-module type. C:\\ projects \\ pj \\ pj.ts(3,1):错误TS2072:模块不能别名为非模块类型。

Based on TypeScript won't resolve external module (node.js) , I'm guessing that the d.ts file is incorrect, but I'm not sure where to go next. 基于TypeScript不能解析外部模块(node.js) ,我猜测d.ts文件不正确,但是我不确定下一步要去哪里。

Seems like an error in the .d.ts indeed. 似乎确实是.d.ts中的错误。 Looks like they forgot to put quotes ("") around the module name: 好像他们忘了在模块名称两边加上引号(“”):

Changing declare module prettyjson { to declare module "prettyjson" { in the .d.ts solved it for me. 更改declare module prettyjson {declare module "prettyjson" {为我解决了它。 Next step would probably be a pull request or a notification to the guys that wrote it. 下一步可能是请求请求或向编写请求的人发送通知。

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

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