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.

Can't use with esbuild

See original GitHub issue

esbuild produces the following error

[error] ✘ [ERROR] Could not resolve "@formkit/auto-animate"
[error]     ../main.js:2:51:
[error]       2 │ ...040formkit$002fauto$002danimate = require("@formkit/auto-animate");
[error]         ╵                                              ~~~~~~~~~~~~~~~~~~~~~~~
[error]   The path "." is not currently exported by package "@formkit/auto-animate":
[error]     ../../../../../node_modules/@formkit/auto-animate/package.json:18:13:
[error]       18 │   "exports": {
[error]          ╵              ^
[error]   None of the conditions provided ("import") match any of the currently active conditions ("browser", "default", "require"):
[error]     ../../../../../node_modules/@formkit/auto-animate/package.json:27:9:
[error]       27 │     ".": {
[error]          ╵          ^
[error]   Consider using an "import" statement to import this file, which will work because the "import" condition is supported by this package:
[error]     ../main.js:2:51:
[error]       2 │ ...040formkit$002fauto$002danimate = require("@formkit/auto-animate");
[error]         ╵                                              ~~~~~~~~~~~~~~~~~~~~~~~
[error]   You can mark the path "@formkit/auto-animate" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.

I guess we need to add default property to package.json:

"exports": {
  ".": {
    "import": "./index.mjs",
    "default": "..."
  }
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
lspoorcommented, Jun 21, 2022

Node - v14.16.0 OS - macOS Catalina 10.15.17

This is the only library I’ve ever had this issue with.

1reaction
hyriouscommented, Jul 10, 2022

I think you can just change "import" to "default" if you don’t want a CJS copy. Or only enforce the rule at node side:

"exports": {
    ".": {
      "node": { "import": "./index.js" },
      "default": "./index.js"
    }
}

I know the reason you’re doing this now is for telling people they cannot require the library. But in fact they can – when they have a bundler. Using default for exporting front-end files is a good practice since we must be careful enough to not including the same library twice (one ESM and another CJS). You can read more about dual package in Node.js’ doc.

For a temporary workaround, you can always write an esbuild plugin / tsconfig.path to manaully resolve a file:

var dedup_auto_animate_plugin = {
  name:"dedup:auto-animate",
  setup(build) {
    build.onResolve({ filter: /^@formkit\/auto-animate$/ }, args => {
      return { path: path.resolve("node_modules/" + args.path + "/index.js") } // didn't test
    })
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started - ESBuild
If you would like to use JSX syntax in .js files instead, you can tell esbuild to ... An additional drawback is that...
Read more >
bug? cant use NODE_OPTIONS with esbuild? #2051 - GitHub
is it possible we can use NODE_PATH environment variable instead of the shell script for esbuilds bin file? see NODE_PATH option in nodejs ......
Read more >
How to fix problems with esbuild in Yarn - DEV Community ‍ ‍
This plugin lets you use Yarn with esbuild. ... But with Yarn 2 PNP, I cannot run node esbuild.config.js in my project because...
Read more >
AWS SAM - Esbuild Failed: cannot find esbuild - Stack Overflow
install esbuild, you can use npm for that ... install esbuild ) - Since esbuild will bundle your code, it won't be packaged...
Read more >
Getting started with esbuild - LogRocket Blog
You'll explore common use cases, from bundling TypeScript, React, image files, and CSS files to serving the bundling process as a server.
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