davidmarkclements / fast-redact

very fast object redaction
MIT License
278 stars 30 forks source link

`createContext is not a function` error thrown in validator.js #37

Closed rushi closed 3 years ago

rushi commented 3 years ago

Hi, I'm trying to use this package in a React app to redact sensitive tokens before logging the information to a remote server and have run into a problem. I'd like some help!

The error in the console is:

validator.js:34 Uncaught Error: fast-redact – Invalid path (headers.cookie)
    at validator.js:34
    at Array.forEach (<anonymous>)
    at validate (validator.js:14)
    at fastRedact (index.js:39)

However when I step into the code and look inside validator.js, the actual exception thrown is createContext is not a function image

Right now I'm simply using the code provided in the Readme, but using an import instead of a require

import fastRedact from "fast-redact";
const redact = fastRedact({
    paths: ["headers.cookie", "headers.referer"],
});
const fauxRequest = {
    headers: {
      host: 'http://example.com',
      cookie: `oh oh we don't want this exposed in logs in etc.`,
      referer: `if we're cool maybe we'll even redact this`
    }
  }
console.log("Redacted Payload", redact(fauxRequest));
mcollina commented 3 years ago

This module is designed to run inside Node and not in the browser... would you like to send a PR to add such support?

jsumners commented 3 years ago

In particular, createContext is a function exported by the vm module provided by Node core.

rushi commented 3 years ago

That's what I assumed, but had to ask.

@mcollina Not interested in working on a PR at the moment.