@@ -35,16 +35,22 @@ const util = require('./rollup.shared');
35
35
// Customize how import.meta.url is polyfilled in cjs nodejs build. We use it to
36
36
// be able to use require() in esm. It only generates the nodejs version of the
37
37
// polyfill, as opposed to the default polyfill which supports both browser and
38
- // nodejs. The browser support is unnecessary and doesn't work well with Jest.
38
+ // nodejs. The browser support doesn't work well with Jest.
39
39
// See https://github.com/firebase/firebase-js-sdk/issues/5687
40
+ // Although this is a cjs Node build and shouldn't require the browser option,
41
+ // Vercel apps using this break on deployment, but work in local development.
42
+ // See https://github.com/firebase/firebase-js-sdk/issues/5823
40
43
function importMetaUrlPolyfillPlugin ( filename ) {
41
44
return {
42
45
name : 'import-meta-url-current-module' ,
43
46
resolveImportMeta ( property , { moduleId } ) {
44
47
if ( property === 'url' ) {
45
- // copied from rollup output
48
+ // Copied from rollup output
49
+ // Added a check for Jest (see issue 5687 linked above)
46
50
return (
47
- "(typeof document === 'undefined' ? new (require('url').URL)" +
51
+ "((typeof document === 'undefined' || process.env.JEST_WORKER_ID " +
52
+ "!== undefined || process.env.NODE_ENV === 'test') ?" +
53
+ " new (require('url').URL)" +
48
54
"('file:' + __filename).href : (document.currentScript && " +
49
55
`document.currentScript.src || new URL('${ filename } ', ` +
50
56
'document.baseURI).href))'
0 commit comments