standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 147 forks source link

`esm/loader.js` logs to terminal on any error #896

Open mjnrock opened 3 years ago

mjnrock commented 3 years ago

Details

esm-index.js

require = require("esm")(module/*, options*/)
module.exports = require("./tests/esm-test.js");

esm-test.js

throw new Error();

Other Details node version: 16.1.0 yarn version: 1.22.10 esm version: 3.2.25 yarn start command: node esm-index.js

Upon running yarn start, if there is (seemingly so far) any error during the execution, the minified contents of esm/loader.js will print to the terminal console. I tried other variations of errors--such as new ClassTest() where ClassTest is undefined, executing a function that does not exist, attempting to import a file that does not exist, typos, etc.-- and all do this.

If I don't compile through esm, these errors do not produce the contents of esm/loader.js. Furthermore, if there are no errors, then the file contents are not produced, either.

Example Error Output This is verbatim, with one exception: the actual file path has been truncated.

--**truncated above this line because of file size length**--
0,enumerable:!0,get(){},set(e){var t=Xn((function(e){return Ns(e,t.options)}),e);return t.options=e.options,t.options.colors=this.useColors,Reflect.defineProperty(Ns,"replDefaults",{configurable:!0,enumerable:!0,get:()=>t.options,set(e){if(!D(e))throw new Hh("options","Object",e);return Pn(t.options,e)}}),N(this,"writer",t),N(Th,"writer",t),t}});var e=Reflect.apply(t,this,[]),i=e.module;return Reflect.defineProperty(R.unsafeGlobal,"module",{configurable:!0,get:()=>i,set(e){i=e,r(i)}}),r(i),e}))),Fa.createScript=e.createScript,qh&&Uh.experimentalREPLAwait&&(Fh.enable(),Vh.enable()),R.support.replShowProxy)N(ni,"inspect",Ns);else{var i=ni.inspect;u(ni,"inspect",oe((function(){return this.inspect=Ns,i}))),c(ni,"inspect",oe((function(e){N(this,"inspect",e)})))}})()},Xh=en.CHECK,Qh=en.CLI,Zh=en.EVAL,ef=en.INTERNAL,tf=en.PRELOADED,rf=en.REPL,nf=en.YARN_PNP,sf=ko.ERR_INVALID_ARG_TYPE,af=R.safeGlobal,of=R.unsafeGlobal;R.inited&&!R.reloaded?(Yn.enable(of),Oh.enable(of),Jh=function(e,t){"use strict";if(!D(e))throw new sf("module","object")r=JSON.stringify({name:Po(e),options:t});return void 0!uest"),""===e)throw new Ch("request",e,"must be a non-empty string");var t=Eu(e,i),r=Pc.state.package.default,n=ge(t);Yc.get(n)===r&&Yc.set(n,r.clone());var s=_c(e,i),a=s.module.exports;return 1!==s.type&&R.bridged.set(a,s),a}),(function(e,t){return Eu(e,i,!1,t)})),n.main=Pc.state.module.mainModule,n}):(Jh=R,Jh.inited=!0,Jh.reloaded=!1,Yn.enable(af),Oh.enable(af),Yn.enable(of),Oh.enable(of),Xh?Yh(Ta):Zh||rf?(_h(bc),Nh(I),Yh(Ta)):(Qh||ef||ch())&&(_h(En),(function(e){"use strict";fh.manage(e,"runMain",(function(t,r,i){var n=I.argv,s=n[1],a=Eu(s,null,!0),o=Yc.from(a),u=fh.find(e,"runMain",dh(o.range));return null===u?Reflect.apply(r,this,i):Reflect.apply(u,this,[t,r,i])})),fh.wrap(e,"runMain",(function(){var 
e,t=I.argv,r=t[1],i=Eu(r,null,!0),n=Pc.state.package.default,s=ge(i);Yc.get(s)===n&&Yc.set(s,n.clone());try{_c(r,null,!0)}catch(e){throw!n.options.debug&&is(e)?ds(e,{filename:i}):fs(e),e}e=O(I,"_tickCallback"),"function"==typeof e&&Reflect.apply(e,I,[])})),bc.runMain=e.runMain})(En),Nh(I)),ef&&(function(e){"use strict";e.console=xo.console.module.exports,e.process=xo.process.module.exports})(of),tf&&nf&&Ih(Ko)),n.default=Jh})]).default;

...\tests\esm-test.js:1
Error
    at Object.<anonymous> (...\tests\esm-test.js:1)
    at Generator.next (<anonymous>)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
curran commented 2 years ago

The same thing is happening to me.

codenomnom commented 2 years ago

+1 for the same issue. Not related to yarn whatsoever - the same happening with npm.

Come on, it's been more than half a year. Any ideas?

georgealways commented 2 years ago

Another plus one from me! thx for the awesome project btw, much love

gbkwiatt commented 2 years ago

Was just looking for solution as it gets annoying. it only happens on ESM import error to me.

georgealways commented 2 years ago

What's funny is that this lib's developer experience (with the error wall) is still preferable to node's --experimental-modules

gbkwiatt commented 2 years ago

What's funny is that this lib's developer experience (with the error wall) is still preferable to node's --experimental-modules

Well.. I've just moved out of esm to --experimental-modules because of that and I am not looking back ;)

georgealways commented 2 years ago

@gbkwiatt I'm jealous! I've tried this more than once and it always requires a non-trivial refactor that looks uglier than what I started with.