0

this is the error:

node:internal/modules/cjs/loader:361 throw err; ^

Error: Cannot find module 'c:\Users\moham\node_modules\faker\index.js'. Please verify that the package.json has a valid "main" entry at tryPackage (node:internal/modules/cjs/loader:353:19) at Function.Module._findPath (node:internal/modules/cjs/loader:566:18) at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27) 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. (c:\Users\moham\Desktop\test\test:1:13) 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) { code: 'MODULE_NOT_FOUND', path: 'c:\Users\moham\node_modules\faker\package.json', requestPath: 'faker' }

this is the code:

var faker = require('faker');

console.log(faker.internet.email());

console.log(faker.date.past());

console.log(faker.address.city());

and I had installed the faker my the code: npm install faker

enter image description here

1 Answers1

1

The last version of faker is 6.6.6. There is a curious story behind it but we leave it for your free time discovery.
Quick fix is to downgrade version of the faker.
Firstly uninstall current version with npm unistall faker then run npm i faker@5.5.3 to install last working version of the package

Jaood_xD
  • 808
  • 2
  • 4
  • 16
  • 1
    That works, but even better would be migrating to the new official fork [@faker-js/faker](https://www.npmjs.com/package/@faker-js/faker) – DivisionByZero Jul 28 '22 at 18:00