Skip to content
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

Node w/ ESM uses CJS files #696

Closed
revmischa opened this issue Mar 27, 2022 · 0 comments · Fixed by #697
Closed

Node w/ ESM uses CJS files #696

revmischa opened this issue Mar 27, 2022 · 0 comments · Fixed by #697
Assignees
Labels
c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug

Comments

@revmischa
Copy link
Contributor

Describe the bug

I'm trying to compile my NodeJS app with ESM. When I build with esbuild, it selects the CJS build of Faker instead of the ESM version.

image

    Checking for a package in the directory "/Users/cyber/dev/platform/node_modules/@faker-js/faker/locale/en_US"
    Read 8 entries for directory "/Users/cyber/dev/platform/node_modules/@faker-js/faker"
    Looking for "./locale/en_US" in "exports" map in "/Users/cyber/dev/platform/node_modules/@faker-js/faker/package.json"
      Checking object path map for "./locale/en_US"
      The key "./locale/*" matched with "en_US" left over
      Checking condition map for one of ["default", "import", "node"]
        The key "node" applies
        Checking path "en_US" against target "./dist/cjs/locale/*.js"
          Substituted "en_US" for "*" in "./dist/cjs/locale/*.js" to get "./dist/cjs/locale/en_US.js"
      The resolved path "/Users/cyber/dev/platform/node_modules/@faker-js/faker/dist/cjs/locale/en_US.js" is exact
      Read 56 entries for directory "/Users/cyber/dev/platform/node_modules/@faker-js/faker/dist/cjs/locale"
      Resolved to "/Users/cyber/dev/platform/node_modules/@faker-js/faker/dist/cjs/locale/en_US.js"
  Read 56 entries for directory "/Users/cyber/dev/platform/node_modules/@faker-js/faker/dist/cjs/locale"
  Ignoring "/Users/cyber/dev/platform/node_modules/@faker-js/faker/tsconfig.json" because "/Users/cyber/dev/platform/node_modules/@faker-js/faker/dist/cjs/locale/en_US.js" is inside "node_modules"
  Primary path is "/Users/cyber/dev/platform/node_modules/@faker-js/faker/dist/cjs/locale/en_US.js" in namespace "file"

Reproduction

I'm using esbuild with --bundle --target node14 --mainFields module,main --format esm

Additional Info

I believe the problem is in faker's package.json:

{
"exports": {
    ".": {
      "node": "./dist/cjs/index.js",
      "es2015": "./dist/esm/index.js",
      "default": "./dist/esm/index.js"
    },
    "./locale/*": {
      "node": "./dist/cjs/locale/*.js",
      "es2015": "./dist/esm/locale/*.js",
      "default": "./dist/esm/locale/*.js"
    },
    "./package.json": "./package.json"
  },
}

It appears to assume if I'm using node I want commonjs. I'm using node and I want ESM.
I think it should be using require vs import - see the nodejs docs here https://nodejs.org/api/packages.html#conditional-exports

Then it will select the proper version depending on if the consumer is using require or import. No assumptions needed.

@revmischa revmischa added the s: pending triage Pending Triage label Mar 27, 2022
@import-brain import-brain added p: 1-normal Nothing urgent s: needs decision Needs team/maintainer decision and removed s: pending triage Pending Triage labels Mar 27, 2022
@Shinigami92 Shinigami92 added s: accepted Accepted feature / Confirmed bug c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs and removed s: needs decision Needs team/maintainer decision labels Mar 27, 2022
@Shinigami92 Shinigami92 moved this to Awaiting Review in Faker Roadmap Mar 27, 2022
@Shinigami92 Shinigami92 added this to the v6.1 - First bugfixes milestone Mar 27, 2022
Repository owner moved this from Awaiting Review to Done in Faker Roadmap Mar 28, 2022
@ST-DDT ST-DDT removed this from Faker Roadmap Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants