Skip to content

ReferenceError: Intl is not defined #2221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
7 of 10 tasks
hellotatia opened this issue Jun 22, 2023 · 9 comments · Fixed by #2222
Closed
7 of 10 tasks

ReferenceError: Intl is not defined #2221

hellotatia opened this issue Jun 22, 2023 · 9 comments · Fixed by #2222
Assignees
Labels
c: bug Something isn't working m: git Something is referring to the git module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Milestone

Comments

@hellotatia
Copy link

hellotatia commented Jun 22, 2023

Pre-Checks

Describe the bug

Hello, I'm trying to use Faker extension and when I run the test, I get the error message on the console:

ReferenceError: Intl is not defined
        at ./node_modules/@faker-js/faker/dist/esm/chunk-2JBE4HP3.mjs (webpack://***/./node_modules/@faker-js/faker/dist/esm/chunk-2JBE4HP3.mjs:4:25475(2732))
        at call (native)
        at __webpack_require__ (webpack://***/webpack/bootstrap:19:0(33))
        at ./node_modules/@faker-js/faker/dist/esm/chunk-BFO2MQ2Q.mjs (webpack://***/./node_modules/@faker-js/faker/dist/esm/chunk-BAJCEGMK.mjs:1:43764(24))
        at call (native)
        at __webpack_require__ (webpack://***/webpack/bootstrap:19:0(33))
        at ./node_modules/@faker-js/faker/dist/esm/index.mjs (webpack://***/./node_modules/@faker-js/faker/dist/esm/chunk-ZVFD5DJO.mjs:1:7399(291))
        at call (native)
        at __webpack_require__ (webpack://***/webpack/bootstrap:19:0(33))
        at ./src/actions/requests/requests.Employee.ts (webpack://***/./src/actions/index.ts:11:69(67))
        at call (native)
        at __webpack_require__ (webpack://***/webpack/bootstrap:19:0(33))
        at webpack://***/webpack/runtime/node%20module%20decorator:5:0(36)
        at file://***/dist/***.bundle.js:23809:3(477)

Minimal reproduction code

No response

Additional Context

package.json devDependencies:

  "devDependencies": {
    "@babel/cli": "^7.21.0",
    "@babel/core": "^7.21.4",
    "@babel/node": "^7.20.7",
    "@babel/plugin-proposal-class-properties": "^7.18.6",
    "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
    "@babel/preset-env": "^7.21.4",
    "@babel/preset-typescript": "^7.21.4",
    "@faker-js/faker": "^8.0.2",
    "@types/mocha": "^10.0.1",
    "@typescript-eslint/eslint-plugin": "^5.57.1",
    "babel-eslint": "^10.1.0",
    "babel-loader": "^9.1.2",
    "eslint": "^8.38.0",
    "eslint-config-prettier": "^8.8.0",
    "eslint-config-standard-with-typescript": "^34.0.1",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-n": "^15.7.0",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-promise": "^6.1.1",
    "prettier": "2.8.7",
    "typescript": "^5.0.4",
    "webpack": "^5.78.0",
    "webpack-cli": "^5.0.1"
  }

import:
import { faker } from '@faker-js/faker';

Environment Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 2.31 GB / 15.73 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (114.0.1823.51)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @faker-js/faker: ^8.0.2 => 8.0.2

Which module system do you use?

  • CJS
  • ESM

Used Package Manager

npm

@hellotatia hellotatia added c: bug Something isn't working s: pending triage Pending Triage labels Jun 22, 2023
@ST-DDT
Copy link
Member

ST-DDT commented Jun 22, 2023

@ST-DDT
Copy link
Member

ST-DDT commented Jun 22, 2023

Please provide a minimal reproduction for this issue.

Is the given system information your dev system or the actual execution environment?

@ST-DDT ST-DDT added the s: awaiting more info Additional information are requested label Jun 22, 2023
@ST-DDT ST-DDT changed the title Error ReferenceError: Intl is not defined Jun 22, 2023
@hellotatia
Copy link
Author

import { faker } from '@faker-js/faker';

export class EmployeeRequest extends BaseRequest {
  constructor() {
    super();
  }

  public registerNewUser() {
    const params: Params = {
      headers: {
        'Content-Type': 'application/json'
      },
    };
    const request: RegisterEmployee = {
      userName: faker.internet.userName(),
      firstName: faker.person.firstName(),
      lastName: faker.person.lastName(),
      email: faker.internet.email()
    };

Given system information is the actual execution environment

@ST-DDT
Copy link
Member

ST-DDT commented Jun 23, 2023

I was unable to reproduce this with the following system setup:

  System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz
    Memory: 55.13 GB / 63.69 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.16.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1848.0), Chromium (114.0.1823.58)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @faker-js/faker: 8.0.2 => 8.0.2

With v8.0.2 it works perfectly fine, I only get an error when I actually try to use a method that uses Intl.*

p [Error]: This method requires an environment which supports Intl.NumberFormat and Intl.DateTimeFormat

In v8.0.1 I cannot run import Faker with the following error message: TypeError: Intl.DateTimeFormat is not a constructor.

AFAICT Node has Intl support for many major versions, so it surprises me that it is missing for you.


I simplified your reproduction to this:

import type { Faker } from "@faker-js/faker";

delete Intl.DateTimeFormat;
delete Intl.NumberFormat;
Intl = undefined;

const { faker } = (await import("@faker-js/faker")) as { faker: Faker };
// const { faker } = require("@faker-js/faker") as { faker: Faker };

const request = {
  userName: faker.internet.userName(),
  firstName: faker.person.firstName(),
  lastName: faker.person.lastName(),
  email: faker.internet.email(),
};

console.log(request);

And was unable to reproduce the error, please provide a working reproduction for this issue.

@ST-DDT
Copy link
Member

ST-DDT commented Jun 23, 2023

chunk-2JBE4HP3.mjs:4:25475

var nr=Intl!=null&&Intl.DateTimeFormat?new Intl.DateTimeFormat("en",{weekday:"short",month:"short",day:"numeric",hour:"2-digit",hourCycle:"h24",minute:"2-digit",second:"2-digit",year:"numeric",timeZone:"UTC"}):null,
ir=Intl!=null&&Intl.NumberFormat?new Intl.NumberFormat("en",{minimumIntegerDigits:4,maximumFractionDigits:0,useGrouping:!1,signDisplay:"always"}):null

Or do we have wrap that in a try catch? (Because Intl isn't defined instead of undefined)

grafik

@hellotatia Can you try to call Intl = undefined; before importing faker just to test that that is the issue?

I would still like to have a way to reproduce the error, so we can actually test, that that fixes the error.

@ST-DDT ST-DDT added s: awaiting more info Additional information are requested and removed s: awaiting more info Additional information are requested labels Jun 23, 2023
@matthewmayer
Copy link
Contributor

i increasingly think the costs of working round Intl bugs in various niche environment outweighs the benefits it brings. Accordingly i tried implementing commitDate in with vanilla JS + formatting functions in #2222

@ST-DDT ST-DDT added p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug m: git Something is referring to the git module and removed s: pending triage Pending Triage s: awaiting more info Additional information are requested labels Jun 23, 2023
@ST-DDT ST-DDT moved this to In Progress in Faker Roadmap Jun 23, 2023
@hellotatia
Copy link
Author

Unfortunately, it doesn't work
Безымянный

With trycatch, but without this part:

delete Intl.DateTimeFormat;
delete Intl.NumberFormat;
Intl = undefined;

image

@ST-DDT
Copy link
Member

ST-DDT commented Jun 23, 2023

Unfortunately, it doesn't work

As a workaround you need an Intl-polyfil. Even if it is an empty one.

globalThis.Intl = undefined;

Sorry, that the first workaround only worked for environments where Intl is available.

With trycatch

The try-catch was for our own/internal code.


But we will remove the usage of Intl in the next version (released probably in July).

@Shinigami92
Copy link
Member

Unfortunately, it doesn't work

As a workaround you need an Intl-polyfil. Even if it is an empty one.

globalThis.Intl = undefined;

Sorry, that the first workaround only worked for environments where Intl is available.

With trycatch

The try-catch was for our own/internal code.


But we will remove the usage of Intl in the next version (released probably in July).

If this works, why not just literally doing globalThis.Intl ??= undefined?!
Looks far more easy to me than doing everything on our own with multiple Date method calls 🤔

@github-project-automation github-project-automation bot moved this from In Progress to Done in Faker Roadmap Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working m: git Something is referring to the git module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants