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

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

 mpvue编译百度小程序,开发者工具打开报错Cannot read property 'createTextNode' of undefined或iphone机型无法预览_第1张图片

 

暂时解决方案:

node_modules/core-js/library/modules/_microtask.js

这里非mpvue问题,出问题的地方在 babel的core-js,这个包里面使用有一个有一个判断优先级调整一下就好
原core-js内异常代码:


// Node.js
  if (isNode) {
    notify = function () {
      process.nextTick(flush);
    };
  // browsers with MutationObserver, except iOS Safari - https://github.com/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-new
    notify = 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 2
    var 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 - https://github.com/zloirock/core-js/issues/339
  } else if (Promise && Promise.resolve) {
    // Promise.resolve without an argument throws an error in LG WebOS 2
    var 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-new
    notify = 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。(此办法一劳永逸,未实验成功,目前采用第二种方法。)

原出处:https://github.com/Meituan-Dianping/mpvue/issues/1352

你可能感兴趣的:(小程序,小程序)