Installing “@faker-js/faker” and getting it to work with Node.js on SublimeText. (I am a beginner level with Sublime and with Node.js)
In Command Prompt (cmd), I was getting error messages when installing and when trying to run this js-file with node. It took me 8-10 hours to get it to work, so I wanted to share if anyone else had this issue.
ISSUE 1: I could not run the installation in the Command Prompt (cmd):
*npm install --save-dev @faker-js/faker*
MY SOLUTION 1: Run Command Prompt (cmd) as Administrator. (Right click the icon to get a menu that gives you and option to “Run as Admin.” And, then run
*npm install --save-dev @faker-js/faker*
ISSUE 2: In SublimeText, I get and error trying to run this file ‘app1.js’ with Node.js. (In SublimeText, I have selected the Tools/Build System/node. And running the script with Ctrl+B)
*const { faker } = require('@faker-js/faker'); *
*console.log(faker.internet.email());*
SUBLIME TEXT CONSOLE ERROR MESSAGE 2:
_node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '@faker-js/faker'
Require stack:
- D:\Dropbox\mySQL Bootcamp\node_and_mysql\app1.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (D:\Dropbox\mySQL Bootcamp\node_and_mysql\app1.js:1:19)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'D:\\Dropbox\\mySQL Bootcamp\\node_and_mysql\\app1.js' ]
}
[Finished in 80ms]_
MY SOLUTION 2:
I noticed that the ‘faker’ module was not saved with the other Node.js modules at C:\Program Files\nodejs\node_modules\ or in npm modules at npm\node_modules)
I searched my computer for ‘*faker*’. I located a folder ‘@faker-js’ at C:\Windows\System32\node_modules.
I updated my js-code to:
*const { faker } = require('C:/Windows/System32/node_modules/@faker-js/faker'); *
*console.log(faker.internet.email());*
Here is the link to GitHub for @faker-js/faker
https://github.com/faker-js/faker