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

Strange error when loading an empty file #1448

kitsonk opened this Issue Jan 3, 2019 · 0 comments


1 participant
Copy link

kitsonk commented Jan 3, 2019

While this is likely a bit of an edge case, it threw me for a loop. If you attempt to load a module in Deno that is empty, you get a cryptic message with a stack trace that doesn't help you. It occured to me where I had stubbed out a test module and had added it to my main test module that imported this empty file.

For example, if you do the following:

$ touch example.ts
$ deno example.ts
Error: No source code.
    at assert (deno/js/util.ts:25:11)
    at _resolveModule (deno/js/compiler.ts:247:5)
    at getFilename (deno/js/compiler.ts:392:33)
    at run (deno/js/runner.ts:174:37)
    at denoMain (deno/js/main.ts:71:12)
    at <anonymous>:1:1

It comes from here:

assert(sourceCode ? sourceCode.length > 0 : false, "No source code.");

Which is an assertion that was a hold over from when we were really concerned about the internals of Deno working properly. I think it is actually legitimate to have an empty module (like when you are stubbing out stuff) and these should result in a no-op, like they would in any other runtime. So I would propose we remove this assertion, because it is actually valid and possible. If not, then we should at least log out the file that it came from so the user is more informed.

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