Skip to content

v0.3.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@jespertheend jespertheend released this 28 Mar 20:32
· 54 commits to main since this release

Better error messages when a network error occurs

When an import fails, previously Deno would only show a generic message that made it difficult to pin down which request failed exactly.
If your script imports from a non existent file on disk for example, it would show

error: Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.

In this update, the dynamic import() will reject with an error that contains the url that caused the import to fail.
This way it is also possible to catch the promise, whereas previously it would throw the error from async code which was uncatchable.

BREAKING: Importing a resource that responds with a non-ok status code throws.

Previously the importer would create a blob from any import, regardless of it's status code. This would likely already cause syntax errors since it is pretty rare for pages with 404 errors to respond with valid JavaScript, but after this update the status code is actually checked, and the dynamic import is rejected in a similar fashion as with failing disk imports.

New redirectModule() method

You can now directly point a module to another file. This is useful if you wish to replace the content of a file with another file, while maintaining the relative import paths from the new file content.

For example, say you have the following files:

// /foo.js
import {bar} from "./bar.js";

// /long/path/to/fakeFoo.js
import {fakeBar} from "./fakeBar.js";

You can point /foo.js to the new path using

importer.redirectModule("/foo.js", "/long/path/to/fakeFoo.js");

Any imports that your fakeFoo.js file contains will remain relative to /long/path/to/, so the fakeBar.js import won't fail in this case.