Reputation: 2305
Right now I have:
"faker": "^5.5.3",
"@types/faker": "^5.5.3",
in my packages.json. I'm using 5.5.3 because there's another dependency in the project (codecept) that's locked to the older version.
The original faker project at https://www.npmjs.com/package/faker seems to have been abandoned. It has a joke version number, no description, etc.
I'd like to use the project that is actively maintained at https://www.npmjs.com/package/@faker-js/faker
But when I try:
"@faker-js/faker": "^5.5.3"
import { faker } from '@faker-js/faker';
(per faker-js documentation)faker.datatype.number(100);
I get:
Cannot read properties of undefined (reading 'datatype')
TypeError: Cannot read properties of undefined (reading 'datatype')
Weirdly, this same code works on a coworker's laptop.
What am I doing wrong? I've tried doing stuff like blowing away node_modules
and starting fresh, and running npm install
, but no luck.
Upvotes: 3
Views: 4280
Reputation: 23915
Changing the import to import faker from '@faker-js/faker'
should solve the problem since faker 5.5.3 uses default imports.
You will however get a compiler error, since this version of faker does not provide its own types. There is also no @types
for this package and the types in @types/faker
do not seem to match the @faker-js/faker
package. So you can do const faker = require('@faker-js/faker)
and continue without having types. But I would recommend to upgrage the @faker-js/faker'
since the newer versions have TypeScript support out of the box.
Upvotes: 4