Failed to execute 'createObjectURL' on 'URL': solution of warning in electron
#97 aberto em 25 de ago. de 2017
Métricas do repositório
- Stars
- (1.068 stars)
- Métricas de merge de PR
- (Métricas PR pendentes)
Description
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.