打字稿错误找不到名称'require'。 IONIC 3 [英] Typescript Error Cannot find name 'require'. IONIC 3
问题描述
打字稿错误
找不到名称'require'。
C:/Users/me/project/src/pages/home/home.ts
//需要Twilio模块并创建REST客户端
Typescript Error Cannot find name 'require'. C:/Users/me/project/src/pages/home/home.ts // require the Twilio module and create a REST client
const client = require('twilio')(accountSid,authToken);
const client = require('twilio')(accountSid, authToken);
Ionic Framework:3.3.0
Ionic Framework: 3.3.0
Ionic App脚本:1.3.7
Ionic App Scripts: 1.3.7
Angular Core:4.1.2
Angular Core: 4.1.2
Angular Compiler CLI: 4.1.2
Angular Compiler CLI: 4.1.2
节点:6.10.3
OS平台:Windows 10
OS Platform: Windows 10
Navigator平台:Win32
Navigator Platform: Win32
用户代理:Mozilla / 5.0(Windows NT 10.0; Win64;
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64;
在home.ts内的CODE:
CODE inside home.ts:
TOP
import { Component } from '@angular/core';
import { FirebaseProvider } from './../../providers/firebase/firebase';
import { FirebaseListObservable } from 'angularfire2/database';
import { NavController, NavParams } from 'ionic-angular';
import { BarcodeScanner ,BarcodeScannerOptions } from '@ionic-native/barcode-scanner';
import { Request } from '@angular/http';
@Component({
selector: 'home',
templateUrl: 'home.html',
})
//警报功能
scanAlert(){
this.options = {
showFlipCameraButton : true,
formats : "QR_CODE,PDF_417",
prompt : "SCAN QR CODE "
}
this.barcodeScanner.scan(this.options).then((barcodeData) => {
console.log(barcodeData);
this.pinText = barcodeData.text;
const uid = this.pinText;
this.firebaseProvider.afd.database.ref('pins')
.orderByChild('QRCODE')
.equalTo(uid)
.limitToFirst(1)
.once('value', snap => {
let key = Object.keys(snap.val())[0]; // KEY VALUE
let user = snap.child(key).val(); // the whole user object
this.message = 'Parameters to send to twilio' + user.phone +
'regarding'+user.message;
const accountSid = 'myacctid';
const authToken = 'mytoken';
// require the Twilio module and create a REST client
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
to: '+142mynumber ',
from: '+mysms trial#',
body: 'TEST Alert Message !',
})
.then((message) => console.log(message.sid));
我按照以下步骤操作
install require --save
install require --save
和
npm install @ types / node --save-dev
npm install @types/node --save-dev
我的问题是邮件没有被发送。
My issue is that the message does not get sent.
如果我添加
declare var require: any
错误发生了离开,但twilio从未得到发送消息的请求。
在此输入图片说明
the error goes away, but twilio never gets the request to send the message. enter image description here
我找不到Ionic3或Angular和twilio的任何教程发送短信
我甚至没有通过参数,我复制了
I cannot find any tutorials for Ionic3 or Angular and twilio to send an sms I have not even passed the parameters, I copied the
我也试过这个
var twilio = require('twilio');//Make sure to npm install @types/node
var accountSid = 'myacctid'; // Your Account SID from www.twilio.com/console
var authToken = 'myauthtoken'; // Your Auth Token from www.twilio.com/console
var client = new twilio(accountSid, authToken);
client.messages.create({
body: 'ALERT! Someone has scanned the Alert Code for ',
to: '+myphone' ,// Text this number
from: '+myTwilioTrial#' // From a valid Twilio number
})
.then((message) => console.log(message.sid));
my tsconfig.json:
my tsconfig.json:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
推荐答案
@ types / node
@types/node
@types
如果 tsconfig.json中有
。 module:node
,则效果最佳
@types
work best if you have module: node
in your tsconfig.json
.
- Potential setup https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html
这篇关于打字稿错误找不到名称'require'。 IONIC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!