Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
Deno: Provide Polyfills for Node.js Built-Ins

Does Deno have a way to shim/polyfill Node.js modules?

That is, let's say I have a typescript file that's part of a Node.js project, and it looks something like this

import { performance } from 'perf_hooks';

function hello() {
  console.log(performance.performance.timeOrigin)
  console.log("Hello World")
}

export {
  hello
}

I want to use this module in a deno program, so I do something like this

import {hello} from './some-module.ts'

function main() {
  hello()
}

However, I can't do this because there's no perf_hooks module in Deno.

% deno run main.ts 
Check file:///private/tmp/main.ts
error: TS2305 [ERROR]: Module '"deno:///none.d.ts"' has no exported member 'performance'.
import { performance } from 'perf_hooks';
         ~~~~~~~~~~~
    at file:///private/tmp/some-module.ts:1:10

I would like to write my own version of perf_hooks that implements the properties and methods I need, and then tell Deno Hey -- whenever anyone wants perf_hook use my module instead.

Does Deno have anything built in that would let me do this? If not is there some common practive/bundling technique that the Deno community uses to do this sort of thing.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use https://deno.land/x/std/node. It provide some Node's built-in modules. For external modules, you can take a look at https://esm.sh (The syntax is https://esm.sh/<npm-pkg>.

And if you want to use it like NodeJS environment, you can do the following:

import { ... } from "module"; // Let's use NodeJS "module" module for this

Then specify an import map

{
  "imports": {
    "module": "https://deno.land/std/node/module.ts"
  }
}

Run with the --import-map flag

$ deno run --import-map=/path/to/import_map.json your_file.ts
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda