Introduction
Today I was trying to use Faker.js for experimenting, but then I saw this:
And I thought, "Well what happened here? Did it get hacked?", so I looked for ways to use it, but no answer.
So I improvised and thought of ways to use it yourself.
1: Use a replacement named Hoaxer.js
I made a replacement named Hoaxer.js to make Faker.js old installation easier.
Instead of using code like this:
var faker = require('faker');
var randomName = faker.name.findName(); // Rowan Nikolaus
var randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
var randomCard = faker.helpers.createCard(); // random contact card containing many properties
Output:
Error: Cannot find module '/home/runner/f4re/node_modules/faker/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:295:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:508:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:802:27)
at Function.Module._load (internal/modules/cjs/loader.js:667:27)
at Module.require (internal/modules/cjs/loader.js:887:19)
at /home/runner/f4re/index.js:1:17
at Script.runInContext (vm.js:130:18)
at Object.<anonymous> (/run_dir/interp.js:209:20)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
You can use it like this so it actually works:
var hoaxer = require('hoaxer');
var randomName = hoaxer.name.findName(); // Rowan Nikolaus
var randomEmail = hoaxer.internet.email(); // Kassandra.Haley@erich.biz
var randomCard = hoaxer.helpers.createCard(); // random contact card containing many properties
Output:
Jeanette Smith III
Doyle.Denesik69@yahoo.com
2: Use Faker.js version ^5.5.3
Instead of using Hoaxer.js, you can also use Faker.js but with a different version.
First run npm install faker@5.5.3
and once done,
include it as usual.
var faker = require('faker');
var randomName = faker.name.findName(); // Rowan Nikolaus
var randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
var randomCard = faker.helpers.createCard(); // random contact card containing many properties
Output:
Jeanette Smith III
Doyle.Denesik69@yahoo.com
Conclusion
In this article we learned it's still possible to use Faker after the mysterious event happened to it. You can either install Hoaxer or Faker.js version ^5.5.3 to use it. Thank you for your time, and see you another time.
Top comments (2)
I was looking for solution everywhere and unable to find it, i am a beginner and this article helped me with my issue I installed mentioned version and wohaa.. its working. Really appreciate your work.
Also decisive for me. Lost a lot of time looking around for this issue/problem. Thanks for the explanation and by-pass solution.