typescript - เกิดข้อผิดพลาดในการนำเข้า stellar-sdk ไปยังโปรเจกต์ angular 8
เรากำลังพยายามพัฒนาแอปเพื่อโต้ตอบกับ Horizon Stellar Server พวกเราเป็นมือใหม่ในด้านนี้และพยายามใช้ Angular 8 และ Ionic 4 แต่เราไม่สามารถนำเข้า js-stellar-sdk ได้สำเร็จ ฉันสร้างแอปใหม่เอาไว้ทดสอบแต่ไม่สามารถคอมไพล์ได้
ลองทำตามนี้: https://stellar.stackexchange.com/questions/1280/using-stellar-sdk-in-angular?rq=1 แต่ผมได้รับข้อผิดพลาดว่า StellarSdk ไม่ถูกกำหนดและ Server ไม่ใช่ตัวสร้าง/ฟังก์ชัน (เมื่อผมคอมเมนต์การประกาศ)
ยังเจออันนี้ด้วย: https://github.com/stellar/js-stellar-base/issues/128 แต่พวกเขาบอกว่ามันถูกแก้ไขแล้ว: https://github.com/stellar/js-stellar-base/issues/128#issuecomment-474474028 อยากลองอันนี้: https://github.com/stellar/js-stellar-base/issues/128#issuecomment-391374590 แต่ดูเหมือนว่ามันไม่ถูกสร้างขึ้นใน Angular 8 แล้ว (ไม่แน่ใจว่าฉันต้องสร้างมันเองไหม)
นี่คือไฟล์ app.component.ts ของฉัน:
import { Component, OnInit } from '@angular/core';
import { Server } from 'stellar-sdk';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
title = 'example';
server: any;
ngOnInit(): void{
this.server = new Server('https://horizon.stellar.org');
}
}
ฉันได้รับข้อผิดพลาดดังต่อไปนี้:
ข้อผิดพลาดใน ./node_modules/eventsource/lib/eventsource.js โมดูลไม่พบ: ข้อผิดพลาด: ไม่สามารถแก้ไข 'http' ใน 'C:\Users\Rafael Cisneros\Desktop\Work\Ionic\example\node_modules\eventsource\lib' ข้อผิดพลาดใน ./node_modules/eventsource/lib/eventsource.js โมดูลไม่พบ: ข้อผิดพลาด: ไม่สามารถแก้ไข 'https' ใน 'C:\Users\Rafael Cisneros\Desktop\Work\Ionic\example\node_modules\eventsource\lib'
คำตอบ #1
ฉันสามารถแก้ปัญหาเดียวกันได้ เรื่องนี้เกี่ยวข้องกับไฟล์ eventsource.js ในเส้นทางนี้: "\node_modules\stellar-sdk\node_modules\eventsource\lib" เปิดไฟล์นั้นและเปลี่ยนสิ่งเหล่านี้:
var https = require('https')
var http = require('http')
ไปยังเหล่านี้:
var https = require('@angular/common/http')
var http = require('@angular/common/http')
นอกจากนี้หากยังไม่ทำงาน ลองพิจารณาเปลี่ยน
import { Server } from 'stellar-sdk';
ตัวอย่างเช่นนี้:
import * as StellarSDK from 'stellar-sdk';
