Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!