1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 编译小程序 开发者工具打开报错Cannot read property ‘createTextNode‘ of un

编译小程序 开发者工具打开报错Cannot read property ‘createTextNode‘ of un

时间:2024-02-01 19:24:05

相关推荐

编译小程序 开发者工具打开报错Cannot read property ‘createTextNode‘ of un

问题描述:运用wepy,编译成百度小程序代码后代开开发者工具报错(或者iphone手机无法预览)。(如下图)

暂时解决方案:

这里非wepy框架问题,出问题的地方在 babel的core-js,这个包里面使用有一个有一个判断优先级调整一下就好

原core-js内异常代码:

// Node.jsif (isNode) {notify = function () {process.nextTick(flush);};// browsers with MutationObserver, except iOS Safari - /zloirock/core-js/issues/339} else if (Observer && !(global.navigator && global.navigator.standalone)) {var toggle = true;var node = document.createTextNode('');new Observer(flush).observe(node, { characterData: true }); // eslint-disable-line no-newnotify = function () {node.data = toggle = !toggle;};// environments with maybe non-completely correct, but existent Promise} else if (Promise && Promise.resolve) {// Promise.resolve without an argument throws an error in LG WebOS 2var promise = Promise.resolve(undefined);notify = function () {promise.then(flush);};// for other environments - macrotask based on:// - setImmediate// - MessageChannel// - window.postMessag// - onreadystatechange// - setTimeout} else {notify = function () {// strange IE + webpack dev server bug - use .call(global)macrotask.call(global, flush);};}

新core-js内代码:

if (isNode) {notify = function () {process.nextTick(flush);};// browsers with MutationObserver, except iOS Safari - /zloirock/core-js/issues/339} else if (Promise && Promise.resolve) {// Promise.resolve without an argument throws an error in LG WebOS 2var promise = Promise.resolve(undefined);notify = function () {promise.then(flush);};// for other environments - macrotask based on:// - setImmediate// - MessageChannel// - window.postMessag// - onreadystatechange// - setTimeout} else if (Observer && !(global.navigator && global.navigator.standalone)) {var toggle = true;var node = document.createTextNode('');new Observer(flush).observe(node, { characterData: true }); // eslint-disable-line no-newnotify = function () {node.data = toggle = !toggle;};// environments with maybe non-completely correct, but existent Promise} else {notify = function () {// strange IE + webpack dev server bug - use .call(global)macrotask.call(global, flush);};}

修改:

1.编译完成后,直接修改vendor.js里的顺序。直接搜索“createTextNode”,找到相应位置修改。但是每次重新编译后需要修改。

2.修改node_module里面node_modules/core-js/library/modules/_microtask.js,相应的顺序,不需要每次编译后修改。但是重新安装core-js后都要修改一遍。

3.去github上fork一份core-js的代码,修改后,安装修改后的core-js。(此办法一劳永逸,未实验成功,目前采用第二种方法。)

编译小程序 开发者工具打开报错Cannot read property ‘createTextNode‘ of undefined或iphone机型无法预览

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。