我的预期标识符错误代码SCRIPT1010出现问题,该代码指向WEBPACK VAR INJECTION部分中的vendor.js。调试器指向以下位置:
const { keccak256, keccak256s } = __webpack_require__(/*! ./hash */ "./node_modules/web3-eth-accounts/node_modules/eth-lib/lib/hash.js");
tsconfig
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2015.promise",
"es2018",
"dom"
]
}
}
polyfils:
import 'classlist.js'
(window as any).__Zone_enable_cross_context_check = true;
index.html:
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
我该怎么解决?请提供提示和意见,谢谢!
以太坊服务正在使用有问题的web3库进行编辑,以太坊服务依赖于hash.js
import { Injectable } from '@angular/core';
import Web3 from 'web3';
import { Block } from 'web3-eth';
import { Observable, BehaviorSubject } from 'rxjs';
const abi = require('../abi/abi.json');
export class TrustedDocumentResponse<T> {
public value: T;
public errorCode: number;
public errorMessage: string;
constructor(value:T, errorCode:number = 0, erroMessage:string = "") {
this.value = value;
this.errorCode = errorCode;
this.errorMessage = erroMessage;
}
}
@Injectable({
providedIn: 'root'
})
export class EthereumService {
web3: Web3;
contract: any;
providers = Object.freeze({
LOCALHOST: 'http://localhost:8546'
});
providerSource = new BehaviorSubject<string>(this.providers.INFURA);
provider$ = this.providerSource.asObservable();
constructor() {
this.provider$.subscribe(provider => {
this.web3 = new Web3(provider);
console.log('eth sub');
});
this.contract = new this.web3.eth.Contract(abi, this.contractAddress);
console.log('contract', this.contract);
}
getBlockTimestamp(blockNumber: number): Promise<Block> {
return this.web3.eth.getBlock(blockNumber);
}
getDocumentIdWithContentHash(hash: string): Promise<any> {
// return this.contract.methods.getDocumentIdWithContentHash(hash).then(result => console.log(result));
console.log('serviceHash: ', hash);
return new Promise<TrustedDocumentResponse<number>>((resolve) => {
//
let transactionObject: any = this.contract.methods.getDocumentIdWithContentHash(hash);
transactionObject.call().then((result) => {
console.log(result);
resolve(new TrustedDocumentResponse<number>(result));
}).catch((reason:Error) => {
console.error(reason);
resolve(new TrustedDocumentResponse<number>(null,1,reason.stack));
});
});
}
getDocument(id: number) {
this.contract.methods.getDocument(id).then(result => console.log(result));
}
convertToBinary(data: any): Uint8Array {
const index = data.indexOf(';base64,') + 8;
const raw = window.atob(data.substring(index));
let array = new Uint8Array(new ArrayBuffer(raw.length));
for (let i = 0; i < raw.length; i++) {
array[i] = raw.charCodeAt(i);
}
return array;
}
}
我希望它会有所帮助。
编辑II
hash.js中的keccak看起来像:
const keccak = bits => str => {
var msg;
if (str.slice(0, 2) === "0x") {
msg = [];
for (var i = 2, l = str.length; i < l; i += 2) msg.push(parseInt(str.slice(i, i + 2), 16));
} else {
msg = str;
}
return update(Keccak(bits, bits), msg);
};
module.exports = {
keccak256: keccak(256),
keccak512: keccak(512),
keccak256s: keccak(256),
keccak512s: keccak(512)
};
答案 0 :(得分:0)
问题是Internet Explorer不支持 Destructuring assignment。
要解决此问题,而不是:
const { keccak256, keccak256s } = __webpack_require__(/*...*/);
您应该使用:
const hash = __webpack_require__(/*...*/),
keccak256 = hash.keccak256,
keccak256s = hash.keccak256s;
答案 1 :(得分:0)
您需要导入es6 polyfills:
import 'core-js/es6/symbol';
import 'core-js/es6/object';
例如,在我的应用中,我有:
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js'; // Run `npm install --save classlist.js`.
/** IE10 and IE11 requires the following for the Reflect API. */
import 'core-js/es6/reflect';
/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
import 'core-js/es7/object';
import 'core-js/es7/array';