简体   繁体   中英

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.

I started with 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

Next I ran tsd install prettyjson --save

I created pj.ts:

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

Finally, I ran 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): error TS2072: Module cannot be aliased to a non-module type.

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.

Seems like an error in the .d.ts indeed. 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. Next step would probably be a pull request or a notification to the guys that wrote it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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