Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mjnrock opened this issue May 21, 2021 · 7 comments
Open

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

mjnrock opened this issue May 21, 2021 · 7 comments

Comments

@mjnrock
Copy link

mjnrock commented May 21, 2021

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
Copy link

curran commented Sep 3, 2021

The same thing is happening to me.

@codenomnom
Copy link

codenomnom commented Nov 4, 2021

+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
Copy link

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

@gbkwiatt
Copy link

gbkwiatt commented Jan 5, 2022

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

@georgealways
Copy link

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

@gbkwiatt
Copy link

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
Copy link

@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.

  • I have a test runner that uses import for dependencies and require to dynamically (and synchronously) load a folder of tests. This turned into a weird promise nightmare with dynamic imports.
  • I import package.json a lot, and node wants even more flags for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants