chromium: [INFO:CONSOLE(10)] "Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode",
source:http://beta.webapp.skysrt.com/yuanbo/test/41834123452234532345423455234523/index.html?theme=dark (10)
Ans: html里匿名函数里使用了let,但没有声明为'use strict'
"Unhandled promise rejection",
source: webpack:///./node_modules/_core-js@3.6.4@core-js/internals/host-report-errors.js? (6)
Ans:
原因是
asyn init() {
await ccApi.tv.init() //原因是这里promise里出错了,不是reject的错误,是在getdeviceinfo前调用getvideosource,顺序错误导致的变量undefined错误,抛出异常
}
解决方法:
async init() {
try {
await ccApi.tv.init()
} catch (e) { //在这里捕获异常
console.error(e)
}
}
Async/Await 中
在 Async/Await 中,unhandled promise rejection 是这样触发:
// Promise 未能阻止异常抛出
;(async () => {
await (new Promise((resolve, reject) => {
reject('timeout');
}));
})();
// async 没有妥善处理异常,需要改为如下:
;(async () => {
try {
await (new Promise((resolve, reject) => {
reject('timeout');
}));
} catch(e) {
throw new Error(e);
}
})();
参考
https://www.jianshu.com/p/232a8cc149d7
https://es6.ruanyifeng.com/#docs/async#%E4%B8%8E%E5%85%B6%E4%BB%96%E5%BC%82%E6%AD%A5%E5%A4%84%E7%90%86%E6%96%B9%E6%B3%95%E7%9A%84%E6%AF%94%E8%BE%83
webpack error
最新推荐文章于 2024-04-17 09:30:51 发布