Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[non-writable] modification of global variable "Promise.prototype.finally" is not allowed when using plugins at app.json #380

Closed
leiroc opened this issue May 13, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@leiroc
Copy link

leiroc commented May 13, 2019

问题描述
在使用插件的情况下,使用Promise ,封装的 uni.request, 提示如下错误:
[non-writable] modification of global variable "Promise.prototype.finally" is not allowed when using plugins at app.json

注意:微信限制在使用插件的时候修改原生属性,Promise.prototype.finally,不可以重写。

复现步骤

  1. app.json 中引入插件
  2. 使用 uni.request Promise 形式调用,(如果不传入 success、fail、complete 等 callback 参数,将以 Promise 返回数据)

参考:

[或者可以直接贴源代码]

/**

  • 根据id获取歌曲
  • @param {String} id
    */
    async function getSongById(id) {
    uni.showLoading({
    title: "加载中..."
    });
    let [error, res] = await uni.request({
    url: URL_SONG,
    header: util.getHttpHeader(),
    data: {
    resourceType: 2,
    resourceId: id
    }
    });
    uni.hideLoading();
    return formatSong(id, res.data);
    }

预期结果
无报错

实际结果
报错:[non-writable] modification of global variable "Promise.prototype.finally" is not allowed when using plugins at app.json

系统信息:

  • 发行平台: [如 微信小程序、H5平台、5+ App等]
  • 操作系统 [如 iOS 12.1.2、Android 7.0]
  • HBuilderX版本 [如使用HBuilderX,则需提供 HBuilderX 版本号]
  • uni-app版本 [如使用Vue-cli创建/运行项目,则提供npm run info的运行结果]
  • 设备信息 [如 iPhone8 Plus]

补充信息

底层对 Promise.prototype.finally,进行了 复写!

fxy060608 added a commit that referenced this issue May 13, 2019
fxy060608 added a commit that referenced this issue May 13, 2019
@fxy060608
Copy link
Collaborator

在开发工具中提示的吗?你用的插件是什么?
我这里集成 wxparser 插件,然后用 uni.request promise 测试没发现有这个错误提示

@leiroc
Copy link
Author

leiroc commented May 13, 2019

我用的是第三方插件,插件需要在 app.json 中注册哦。工具是微信调试工具,最新的版本。 @fxy060608

"usingComponents": true,
"requiredBackgroundModes": ["audio"],
"plugins": {
"myPlugin": {
"version": "1.0.7",
"provider": "wx80b5f24d05ef8e63"
}
},

源码报错地址是下面的代码:

Promise.prototype.finally

function promisify (name, api) {
if (!shouldPromise(name)) {
return api
}
return function promiseApi (options = {}, ...params) {
if (isFn(options.success) || isFn(options.fail) || isFn(options.complete)) {
return api(options, ...params)
}
return handlePromise(new Promise((resolve, reject) => {
api(Object.assign({}, options, {
success: resolve,
fail: reject
}), ...params);
/* eslint-disable no-extend-native */
Promise.prototype.finally = function (callback) {
const promise = this.constructor;
return this.then(
value => promise.resolve(callback()).then(() => value),
reason => promise.resolve(callback()).then(() => {
throw reason
})
)
};
}))
}
}

@leiroc
Copy link
Author

leiroc commented May 13, 2019

@fxy060608 如上。

@fxy060608
Copy link
Collaborator

我也是用的三方插件做测试,没有提示报错,微信开发者工具是哪个版本,版本号贴出来

@leiroc
Copy link
Author

leiroc commented May 13, 2019

版本号:1.02.1905081 @fxy060608

@fxy060608 fxy060608 added the bug Something isn't working label May 13, 2019
@fxy060608
Copy link
Collaborator

已确认,你使用的微信开发者工具是预发布版本,可以先使用稳定版,稍后修复此问题

fxy060608 added a commit that referenced this issue May 13, 2019
@leiroc
Copy link
Author

leiroc commented May 13, 2019

好,很给力! @fxy060608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants