The development team behind the JavaScript and TypeScript runtime Deno has published a release candidate for version 2.0. The biggest update since version 1.0 will bring significant new features to the Node.js alternative, such as the introduction of Node.js global variables process
. All expected features of the final version are already included in the current release candidate.
Advertisement
Global variables: window goes, process comes
Global variables window
Deno has been on board since 1.0 and the aim was to make Deno as browser-compatible as possible. However, this variable caused some difficulties for users, so the Deno team decided to use the option from version 1.40 globalThis
Or self
Fall back. window
Now in version 2.0, we will leave:
// Deno v1.x
window.addEventListener("load", () => {
console.log("loaded");
});
// Deno v2.x
globalThis.addEventListener("load", () => {
console.log("loaded");
});
Difficulty in global availability of window
was that many libraries check if they are running in the browser by searching window
variables instead of the DOM – which led to many bugs in libraries that would otherwise work in Deno.
The new global variable is in the release candidate process
is ready, which according to the development team was most frequently requested by users. So far it has been possible process
By importing node:process
modules, but many popular frameworks rely on the global availability of variables. By adding process
Significantly more code that was originally written for Node.js should now run in Deno without any changes.
However, the Deno team still recommends preferring explicit imports. So it has a new lint rule no-process-global
Added , which will provide corresponding hints and quick solutions in the editor.
(Image: Jacky Niam/Shutterstock.com)
The online conference will be presented on October 17, 2024 Feedback 19 days New features of the popular JavaScript library from dpunkt.verlag and iX. Theme day as part of EnterJS Shows participants how they can make the most of the new version and how modern web development with React 19 improves their applications. Excerpt from the event:
early bird tickets Available till 25th September.
Updated dependency management
Deno 2.0 brings some new functions for managing dependencies. Among other things, deno add
The -subcommand specifier now with a subpath, as the Deno team demonstrates compared to the current version 1.46:
# Zuvor in Deno v1.46
deno add jsr:@std/testing/snapshot
error: Failed to parse package required: @std/testing/snapshot
Caused by:
0: Invalid package requirement '@std/testing/snapshot'. Invalid version requirement. Invalid specifier version requirement. Unexpected character '/'
...
# Deno v2.0
deno add jsr:@std/testing/snapshot
Add jsr:@std/testing@1.0.2
# Deno v1.46
deno add npm:preact/hooks
error: Failed to parse package required: npm:preact/hooks
Caused by:
0: Invalid package requirement 'preact/hooks'. Packages in the format / must start with an '@' symbol.
1: Packages in the format / must start with an '@' symbol.
# Deno v2.0
deno add npm:preact/hooks
Add npm:preact@10.24.0
When adding dependencies there are now jsr:
– Or npm:
-n Prefix required to prevent possible ambiguity between packages with the same name in both registries.
API has been stabilized and removed
The three APIs are now considered stable and so one is no longer needed --unstable
-flag: WebGPU
, Deno.dlopen()
And Deno.createHttpClient()
. In addition, the development team has also modified the error messages to provide helpful hints when trying to use the unstable API without the corresponding flag.
Downward incompatible changes include the removal of a large number of APIs. These include Deno.Buffer
, Deno.close()
And Deno.copy()
. Five APIs are considered “soft-deprecated” and will continue to work but will not receive updates or bug fixes. Therefore, the Deno team recommends migrating to their stable counterparts:
Deno.serveHttp()
– insteadDeno.serve()
To useDeno.run()
– new insteadDeno.Command()
To useDeno.isatty(Deno.stdin.rid)
– insteadDeno.stdin.isTerminal()
To useDeno.isatty(Deno.stdout.rid)
– insteadDeno.stdout.isTerminal()
To useDeno.isatty(Deno.stderr.rid)
– insteadDeno.stderr.isTerminal()
To use
Feedback wanted before final release
The purpose of the Release Candidate is to help uncover potential issues before the major release Deno 2.0 is released. Therefore, the Deno team is actively looking for feedback from developers, either by making Open an issue on GitHub or by contacting us in the Discord channel #deno-2-help,
All additional details about the release candidate Deno Offers Blog,
(May)