简体   繁体   中英

Using Github's Node-Trello in Ionic 2 - Error TS2304: Cannot find name 'require'

newbee to ionic2, angular2 and programmatic access to Trello.

I would like to use this wrapper in ionic, but can't declare the node-trello module.

I have installed node-trello:

npm install node-trello --save

which updated my package.json : Please see dependencies section of my package.json "node-trello" has version "^1.1.2"

{
    "dependencies": {
        "@angular/common": "2.0.0-rc.3",
        "@angular/compiler": "2.0.0-rc.3",
        "@angular/core": "2.0.0-rc.3",
        "@angular/http": "2.0.0-rc.3",
        "@angular/platform-browser": "2.0.0-rc.3",
        "@angular/platform-browser-dynamic": "2.0.0-rc.3",
        "es6-shim": "^0.35.0",
        "ionic-angular": "2.0.0-beta.10",
        "ionic-native": "1.2.4",
        "ionicons": "3.0.0",
        "minimatch": "^3.0.2",
        "node-trello": "^1.1.2",
        "reflect-metadata": "^0.1.3",
        "rxjs": "5.0.0-beta.6",
        "trello": "^0.5.1",
        "zone.js": "^0.6.12"
    }
}

Have tried as the author says on his website

var Trello = require("node-trello");

But I get the following error despite the fact that /node-modules/node-trello directory exists.:

TypeScript error: C:/workspace/.......etc...../Service.ts(26,22): Error TS2304: Cannot find name 'require'.

You are using typescript, so it should be

import Trello = require("node-trello");

or

import * as Trello from "node-trello";

EDIT: this should work at runtime, if your modules are being loaded correctly, however it will still show an error during compilation. To get rid of the error, you have to provide typescript with the module declarations. Normally you would download the declarations from npm or Typings, but I didn't find them for the node-trello package, so you have to provide your own. You can put this into your declarations file:

declare module "node-trello" {
    const value: any;
    export default value;
}

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