thlorenz/brace

Failed to execute 'createObjectURL' on 'URL': solution of warning in electron

Open

#97 创建于 2017年8月25日

在 GitHub 查看
 (0 评论) (4 反应) (0 负责人)JavaScript (295 fork)github user discovery
bughelp wanted

仓库指标

Star
 (1,068 star)
PR 合并指标
 (PR 指标待抓取)

描述

Since #54 can't be commented, pardon me for opening a new issue here.

Using webpack with electron, we usually set webpack config with target: 'electron-renderer', which leads to warning like Failed to execute 'createObjectURL' on 'URL'.

I've found out the reason is that brace use w3c-blob to obtain Blob object, and w3c-blob provide two version of Blob - one for browser environment and one for node environment, as you can see there're field named 'browser' and field named 'main' in its package.json.

window.URL.createObjectURL expect an instance of window.Blob, but Webpack packs the node version, which gives brace the wrong Blob object, so we get the warning.

My solution is adding this in my webpack config:

resolve: {
        mainFields: ["browser", "module", "main"]
},

In that way we force webpack to first pick the 'browser' field of a package.json, so that brace could get the right Blob object, and the warnings are gone.

This might be a bug of webpack, but since it might help people using webpack & brace & electron, here I write it down.

贡献者指南