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

179
Visualizações
rollup js to include NodeJS core library

I was deploying something onto an akamai edgeworker and hence was using the node package rollup. One of the packages i have uses require('crypto') which causes issues for me as i cant seem to get the rollup to include the code. I was able to work around and get it so i dont have the import at the top but now getting TypeError: crypto.randomFillSync is not a function. just wondering how i can deploy something that requires crypto onto edgeworker. my current rollup.config file is:

banner.js

var window = {};
var TextDecoder = function() {};
var setTimeout = function(callback) { callback(); };

rollup.config.js

import * as fs from "fs";
import resolve from "@rollup/plugin-node-resolve";
import json from "@rollup/plugin-json";
import commonjs from "@rollup/plugin-commonjs";
import nodePolyfills from 'rollup-plugin-node-polyfills';
import { babel } from '@rollup/plugin-babel';


const BANNER = fs.readFileSync("./src/banner.js").toString();

function getPlugins(babelConfig) {
  return [
    // Convert CommonJS modules to ES6
    commonjs(),
    nodePolyfills(),
    // Resolve modules from node_modules
    resolve({
      // use the "browser" property in package.json
      browser: true,
      preferBuiltins: false
    }),
    babel(babelConfig),
    // Package json data as an ES6 module
    json()
  ];
}

export default [
  {
    input: "src/index.js",
    output: {
      banner: BANNER,
      name: "main",
      file: "dist/main.js",
      format: "esm",
      sourcemap: false
    },
    external: ['cookies', 'http-request', 'log', 'create-response'],
    plugins: getPlugins(
      {
        inputSourceMap: true,
        sourceMaps: true,
        exclude: ["node_modules/**", /\/core-js\//],

        presets: [
          [
            "@babel/preset-env",
            {
              useBuiltIns: "usage",
              corejs: 3,
              modules: false,
              targets: {
                browsers: [
                  "last 2 Chrome versions",
                  "last 2 Firefox versions",
                  "last 2 Safari versions"
                ]
              }
            }
          ]
        ],
        plugins: []
      }
    )
  }
];

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

0

the crypto module relies on having either a Node.js or a browser environment, as it provides the implementation by wrapping the underlying platform APIs. Akamai EdgeWorkers does not yet provide a native crypto functionality, so you would need to use a JS library which provides a pure JS implementation.

I have had success with using crypto-es (https://www.npmjs.com/package/crypto-es) as long as you are careful to watch CPU limits.

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