question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interpreting exports fields in package.json

See original GitHub issue

This is related to this issue in the bezier-js library.

That library has the following targets specified in its package.json: https://github.com/Pomax/bezierjs/blob/cb4fe3e55add7401bdc5ee56ada46abb61b55883/package.json#L6-L11

  "type": "module",
  "exports": {
    "import": "./src/bezier.js",
    "require": "./dist/bezier.cjs"
  },
  "main": "./dist/bezier.cjs",

Yet, when an app created with react-scripts encounters import { Bezier } from "bezier-js", it will incorrectly link to the commonJs file (dist/bezier.cjs), not the ES modulesrc/bezier.js as specified there. This in turn causes an error because the named import Bezier does not exist on the cjs bundle. That means every app created with create-react-app that has bezier-js in its dependency tree will fail the build, as can be seen here: https://github.com/vasturiano/force-graph/issues/182 and here: https://github.com/vasturiano/react-force-graph/issues/282.

Other popular bundlers like webpack and rollup don’t seem to have this issue, and correctly target the ES module file in the import.

I’ve made a simple sandbox that reproduces the issue with react-scripts: https://codesandbox.io/s/create-react-app-import-bezier-js-5fxc4

I’m not sure if this a known issue or whether it is already resolved in some way. I’ve searched in the issues and couldn’t find anything obvious related.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:26
  • Comments:7

github_iconTop GitHub Comments

11reactions
Pomaxcommented, Jan 28, 2022

There should not be a “stale bot” acting on an issue with 26 upvotes - instead, it should bump up this issue for triage, since that still hasn’t happened.

(a stale bot should only threatening to close an issue after it has been triaged and responded to by someone on the team, not because no one in the team has have over a year’s worth of time to even look at it)

10reactions
captainR0bbocommented, Oct 1, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.JS (New) Package.json Exports Field - Medium
The exports field (or “export map”) provides a way to expose your package modules for different environments and JavaScript flavors WHILE ...
Read more >
Package exports - webpack
The exports field in the package.json of a package allows to declare which module should be used when using module requests like import...
Read more >
Modules: Packages | Node.js v19.3.0 Documentation
In a package's package.json file, two fields can define entry points for a package: "main" and "exports" . Both fields apply to both...
Read more >
How to make IntelliSense aware of exports in package.json?
Meaning, you have set certain fields in both your package.json & tsconfig.json files that conflict with other settings within those same ...
Read more >
Support "exports" field of package.json : WEB-40509 - YouTrack
Support "exports" field of package.json · Auto-imports don't work for referenced external packages in "imports" mappings. · Exclude subfolders from patterns with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found