Deno adds package.json support

Deno 1.31 automatically detects package.json and uses it to install and resolve dependencies, making it easier to move from Node.js.

shutterstock 1591493512 dinosaur roadside attraction brontosaurus T Rex clouds blue sky
The Image Party / Shutterstock

Deno 1.31, the latest version of the Node.js rival runtime for JavaScript, TypeScript, and WebAssembly, adds package.json support. The new feature is one of several improvements designed to make it easier for developers to transition from existing Node.js projects.

Deno now will automatically detect a package.json and use it to install and resolve dependencies used. This also enables the running of project-specific scripts defined in the scripts section with deno task. However, current support is limited to simple scripts. Programs such as rimraf or cross-env will not yet work, but support for them will be added in an upcoming release.

Deno 1.31 also stabilizes the Node-API (N-API). Developers no longer need use the unstable flag when using NPM packages that rely on this API. Many bug fixes were applied to Node-API and more packages can be used without issue. Remaining bugs will be addressed in upcoming weeks.

In addition, Deno 1.31 moves the compatibility layer for Node.js directly into the Deno runtime. Previously, compatibility for Node.js was provided by using https:/, a collection of polyfills in userland code in the Deno standard library. Because dependency on had to be bumped with each release of Deno, the compatibility layer had to downloaded after each upgrade. Now the compatibility layer is embedded in the runtime and V8 JavaScript engine snapshots are used to reduce startup time. The tighter integration enables easier polyfilling of missing APIs and improves the performance of built-in Node.js modules. To use embedded polyfills, developers can import from node: specifiers

Unveiled February 24, Deno 1.31 can be accessed via deno upgrade for current users. Other installation options are listed on GitHub. Deno 1.31 follows last month’s release of Deno 1.30, which improved support for Node.js modules.

Also in Deno 1.31:

  • In a breaking change, pointers now are represented as plain objects, or null for null pointers. These objects are created by V8 and supported by V8 Fast API, improving performance of FFI (Foreign Function Interface) when working with “pointer” type parameters and return values from previous versions. Pointer objects are opaque and cannot be manipulated directly from JavaScript. Thus, FFI becomes safer to use, with pointer spoofing no longer as easy as writing a JavaScript number. Note that the FFI API is unstable.
  • The Deno.Command and Deno.osUptime() APIs now are stabilized. Developers are advised to migrate from the API to Deno.Command.
  • The API now returns more variants for operating systems, such as "darwin", "linux", "windows", and "solaris".
  • For the standard library, modules for have been removed. This code is now directly embedded in the Deno runtime.
  • For the command interface, the deno bundle command is no longer supported and will not show up in the help output.
  • Also for the CLI, deno benchcode now accepts a --json flag that will print benchmark results as JSON.
  • The interactive permission prompt now accepts a new option, A. This option enables granting of permission for subsequent calls to APIs using the granted domain.
  • deno compile now understands dynamic imports that can be resolved at compile time.

Copyright © 2023 IDG Communications, Inc.