JavaScript Runtime Gotchas
This document covers some edge cases and gotchas with the javascript runtime.
__proto__
property of objects:
The Deno runtime does not support the __proto__
property of objects. This is a deprecated feature of the JavaScript language and should not be used in modern code. Instead, use Object.getPrototypeOf
and Object.setPrototypeOf
to get and set the prototype of an object. The following discussion on Deno’s GitHub elaborates: https://github.com/denoland/deno/issues/4324.
However because Node still supports __proto__
many NPM libraries still use __proto__
and will break in Deno. To fix this, you can add the following code to the top of your program:
As the __proto__
is non-standard in Deno and poses a security risk, we have chosen not to add this workaround to the runtime by default, but rather let developers add it ad-hoc to their programs. We hope libraries will migrate away from using __proto__
in the future.
process.versions
missing:
In node js, you can access the version of the node runtime using process.versions
. This is not available in Deno by default - meaning that NPM libraries that rely on this will break in Deno. This can manifest as an error like Cannot read property 'node' of undefined
.
To fix this, you can add the following code to the top of your program:
Reference: https://docs.deno.com/api/node/process/~/Process.versions