Repository navigation
Description
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Metro 0.65.0 (and 0.65.1) produces an invalid bundle for the following code:
helloWorld.js:
export default function () { console.log('hello world'); }index.js:
import helloWorld from './helloWorld';
helloWorld();node bundle.js throws error:
ReferenceError: _interopRequireDefault is not defined
With "metro" 0.64.0 or below there is no such issue. I've compared bundled produced by both versions and it looks like in 0.65.1 bodies are not bundled for both interopRequireDefault and helloWorld functions.
0.65.1:
var __BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now(),__DEV__=false,process=this.process||{},__METRO_GLOBAL_PREFIX__='';process.env=process.env||{};process.env.NODE_ENV=process.env.NODE_ENV||"production";
!(function(r){"use strict";r.__r=o,r["".concat(__METRO_GLOBAL_PREFIX__,"__d")]=function(r,i,n){if(null!=e[i])return;var o={dependencyMap:n,factory:r,hasError:!1,importedAll:t,importedDefault:t,isInitialized:!1,publicModule:{exports:{}}};e[i]=o},r.__c=n,r.__registerSegment=function(r,t,i){s[r]=t,i&&i.forEach(function(t){e[t]||v.has(t)||v.set(t,r)})};var e=n(),t={},i={}.hasOwnProperty;function n(){return e=Object.create(null)}function o(r){var t=r,i=e[t];return i&&i.isInitialized?i.publicModule.exports:d(t,i)}function l(r){var i=r;if(e[i]&&e[i].importedDefault!==t)return e[i].importedDefault;var n=o(i),l=n&&n.__esModule?n.default:n;return e[i].importedDefault=l}function u(r){var n=r;if(e[n]&&e[n].importedAll!==t)return e[n].importedAll;var l,u=o(n);if(u&&u.__esModule)l=u;else{if(l={},u)for(var a in u)i.call(u,a)&&(l[a]=u[a]);l.default=u}return e[n].importedAll=l}o.importDefault=l,o.importAll=u;var a=!1;function d(e,t){if(!a&&r.ErrorUtils){var i;a=!0;try{i=h(e,t)}catch(e){r.ErrorUtils.reportFatalError(e)}return a=!1,i}return h(e,t)}var c=16,f=65535;function p(r){return{segmentId:r>>>c,localId:r&f}}o.unpackModuleId=p,o.packModuleId=function(r){return(r.segmentId<<c)+r.localId};var s=[],v=new Map;function h(t,i){if(!i&&s.length>0){var n,a=null!==(n=v.get(t))&&void 0!==n?n:0,d=s[a];null!=d&&(d(t),i=e[t],v.delete(t))}var c=r.nativeRequire;if(!i&&c){var f=p(t),h=f.segmentId;c(f.localId,h),i=e[t]}if(!i)throw Error('Requiring unknown module "'+t+'".');if(i.hasError)throw _(t,i.error);i.isInitialized=!0;var m=i,g=m.factory,I=m.dependencyMap;try{var M=i.publicModule;return M.id=t,g(r,o,l,u,M,M.exports,I),i.factory=void 0,i.dependencyMap=void 0,M.exports}catch(r){throw i.hasError=!0,i.error=r,i.isInitialized=!1,i.publicModule.exports=void 0,r}}function _(r,e){return Error('Requiring module "'+r+'", which threw an exception: '+e)}})('undefined'!=typeof globalThis?globalThis:'undefined'!=typeof global?global:'undefined'!=typeof window?window:this);
__d(function(g,r,i,a,m,e,d){"use strict";(0,_interopRequireDefault(r(d[0])).default)()},0,[1]);
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=_default},1,[]);
__r(0);
0.64.0:
var __BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now(),__DEV__=false,process=this.process||{},__METRO_GLOBAL_PREFIX__='';process.env=process.env||{};process.env.NODE_ENV=process.env.NODE_ENV||"production";
!(function(r){"use strict";r.__r=o,r["".concat(__METRO_GLOBAL_PREFIX__,"__d")]=function(r,i,n){if(null!=e[i])return;var o={dependencyMap:n,factory:r,hasError:!1,importedAll:t,importedDefault:t,isInitialized:!1,publicModule:{exports:{}}};e[i]=o},r.__c=n,r.__registerSegment=function(r,t,i){s[r]=t,i&&i.forEach(function(t){e[t]||v.has(t)||v.set(t,r)})};var e=n(),t={},i={}.hasOwnProperty;function n(){return e=Object.create(null)}function o(r){var t=r,i=e[t];return i&&i.isInitialized?i.publicModule.exports:d(t,i)}function l(r){var i=r;if(e[i]&&e[i].importedDefault!==t)return e[i].importedDefault;var n=o(i),l=n&&n.__esModule?n.default:n;return e[i].importedDefault=l}function u(r){var n=r;if(e[n]&&e[n].importedAll!==t)return e[n].importedAll;var l,u=o(n);if(u&&u.__esModule)l=u;else{if(l={},u)for(var a in u)i.call(u,a)&&(l[a]=u[a]);l.default=u}return e[n].importedAll=l}o.importDefault=l,o.importAll=u;var a=!1;function d(e,t){if(!a&&r.ErrorUtils){var i;a=!0;try{i=h(e,t)}catch(e){r.ErrorUtils.reportFatalError(e)}return a=!1,i}return h(e,t)}var c=16,f=65535;function p(r){return{segmentId:r>>>c,localId:r&f}}o.unpackModuleId=p,o.packModuleId=function(r){return(r.segmentId<<c)+r.localId};var s=[],v=new Map;function h(t,i){if(!i&&s.length>0){var n,a=null!==(n=v.get(t))&&void 0!==n?n:0,d=s[a];null!=d&&(d(t),i=e[t],v.delete(t))}var c=r.nativeRequire;if(!i&&c){var f=p(t),h=f.segmentId;c(f.localId,h),i=e[t]}if(!i)throw Error('Requiring unknown module "'+t+'".');if(i.hasError)throw _(t,i.error);i.isInitialized=!0;var m=i,g=m.factory,I=m.dependencyMap;try{var M=i.publicModule;return M.id=t,g(r,o,l,u,M,M.exports,I),i.factory=void 0,i.dependencyMap=void 0,M.exports}catch(r){throw i.hasError=!0,i.error=r,i.isInitialized=!1,i.publicModule.exports=void 0,r}}function _(r,e){return Error('Requiring module "'+r+'", which threw an exception: '+e)}})('undefined'!=typeof globalThis?globalThis:'undefined'!=typeof global?global:'undefined'!=typeof window?window:this);
__d(function(g,r,i,a,m,e,d){"use strict";var t;(0,((t=r(d[0]))&&t.__esModule?t:{default:t}).default)()},0,[1]);
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(){console.log('hello world')}},1,[]);
__r(0);
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.
https://github.com/nikoant/metro-0.65-bug-repro
What is the expected behavior?
The produced bundle should run without any errors.
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
Metro 0.65.1, yarn 1.22.4, macOS 10.15.7
Activity
MichaReiser commentedon Mar 2, 2021
Thanks @nikoant for reporting this bug. I tried to run the repo locally but it failed with:
Because ES Modules are not lowered to CommonJS. One can then either enable
experimentalImportSupportin themetro.config.jswhich worksor add a
babel.config.jswhich allows your reported issue{ "presets": [], "plugins": [ "@babel/plugin-transform-modules-commonjs" ] }MichaReiser commentedon Mar 2, 2021
I narrowed the issue down to 279b295, specifically to no longer cloning the input AST. It isn't clear to me why it's causing issues but will go ahead and revert the change.
nikoant commentedon Mar 2, 2021
Oops, sorry, in the initial repo I had "@babel/preset-env", but then while trying to narrow it down I removed babel, but was still able to build the bundle. Now I see it was because of Metro cache, because if I call build with "--reset-cache" after removing babel it shows the error you mentioned. I just updated the repo and returned the initial version with babel. However the produced bundle is broken anyway.
nikoant commentedon Mar 2, 2021
Thanks for looking into this!
MichaReiser commentedon Mar 3, 2021
This issue should now be resolved and I just scheduled the release of 0.65.2.
Fixed 63f3d1e
Metro and Babel upgraded
Experiment: skip AST cloning in the transform worker (#2033)
Experiment: skip AST cloning in the transform worker (#2033)
Stop cloning the AST in the transform worker's main Babel pass (#2034)
Experiment: skip AST cloning in the transform worker (#2033)
Experiment: skip AST cloning in the transform worker
Stop cloning the AST in the transform worker's main Babel pass (#2034)
Experiment: skip AST cloning in the transform worker (#2033)
Experiment: skip AST cloning in the transform worker (#2033)
Stop cloning the AST in the transform worker's main Babel pass (#2034)
Experiment: skip AST cloning in the transform worker (#2033)
Experiment: skip AST cloning in the transform worker
Stop cloning the AST in the transform worker's main Babel pass (#2034)
Experiment: skip AST cloning in the transform worker (#2033)
Stop cloning the AST in the transform worker's main Babel pass (#2034)
Experiment: skip AST cloning in the transform worker (#2033)
Experiment: skip AST cloning in the transform worker (#2033)
Stop cloning the AST in the transform worker's main Babel pass (#2034)
Experiment: skip AST cloning in the transform worker (#2033)