gpt4 book ai didi

node.js - typescript 错误找不到名称 'require'。 ionic 3

转载 作者:搜寻专家 更新时间:2023-10-30 21:23:41 25 4
gpt4 key购买 nike

typescript 错误找不到名称“require”。C:/Users/me/project/src/pages/home/home.ts //需要 Twilio 模块并创建一个 REST 客户端

const client = require('twilio')(accountSid, authToken);

ionic 框架:3.3.0

Ionic 应用程序脚本:1.3.7

Angular 核心:4.1.2

Angular 编译器 CLI:4.1.2

Node :6.10.3

操作系统平台:Windows 10

导航器平台:Win32

用户代理:Mozilla/5.0 (Windows NT 10.0; Win64;

ts code

home.ts 中的代码:

顶部

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));

我遵循了这些步骤

安装需要--保存

npm install @types/node --save-dev

我的问题是消息未发送。

如果我添加

declare var require: any    

错误消失了,但 twilio 从未收到发送消息的请求。 enter image description here

我找不到任何 Ionic3 或 Angular 和 twilio 发送短信的教程我连参数都没有传,我复制了

这个我也试过

    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));

我的 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"
],
"typeRoots": [
"node_modules/@types"
]

tsconfig.json文件中

关于node.js - typescript 错误找不到名称 'require'。 ionic 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44424834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com