如何将节点模块creditcard与Ionic 3一起使用?
实施的例子是:
var Card = require('creditcards/card')
var card = Card([visa])
card.isValid('4242424242424242')
// => true
var expiration = require('creditcards/expiration')
expiration.isPast(10, 2010)
// => true
但是使用Ionic 3我收到了错误Cannot find name 'require'.
我在离子中发现lodash
的类似问题:https://github.com/ionic-team/ionic/issues/8274
我尝试过发布的解决方案,但似乎都没有。
首先我尝试添加import card from 'creditcards/card';
这是离子代码:
import { Component } from '@angular/core';
import card from 'creditcards/card';
@Component({
templateUrl: 'creditcard.html'
})
export class CreditcardPage {
creditContent: string;
constructor() {
this.creditContent = card.isValid(`42424242424242`);
}
}
我收到错误ReferenceError: card is not defined
。
我尝试了import 'creditcards/card';
:
import { Component } from '@angular/core';
import 'creditcards/card';
@Component({
templateUrl: 'creditcard.html'
})
export class CreditcardPage {
creditContent: string;
constructor() {
this.creditContent = card.isValid(`42424242424242`);
}
}
我收到错误Uncaught ReferenceError: Card is not defined
SO中还有一个帖子:Typescript Error Cannot find name 'require'. IONIC 3。这不提供相关信息,因为它特定于@types/node
。
答案 0 :(得分:1)
我认为问题出在您的tsconfig文件中。您应该包含'types:[node]'