Skip to content

How to fix "require is not defined"? #1321

Answered by FredKSchott
DynamicArray asked this question in Q&A
Discussion options

You must be logged in to vote

Usually this happens when a package tells us that it's ESM but it then still contains CJS require() calls. If a package tells us it's ESM we'll trust it, but in some cases that's not true.

A quick look at jotai's ESM code seems fine (https://unpkg.com/browse/[email protected]/index.js) but then it imports use-context-selector, which does mix ESM & CJS: https://unpkg.com/browse/[email protected]/dist/index.modern.js

We can add a workaround for this specific package, but only if the package author is unresponsive. Can you file an issue with that repo for them to solve on their end? All Rollup projects would be affected by this issue and unable to use this package, so it's probably a bigg…

Replies: 9 comments 14 replies

Comment options

You must be logged in to vote
1 reply
@DynamicArray
Comment options

Answer selected by DynamicArray
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@FredKSchott
Comment options

Comment options

You must be logged in to vote
5 replies
@FredKSchott
Comment options

@xialvjun
Comment options

@nrgapple
Comment options

@mengbo-ji
Comment options

@theseyi
Comment options

Comment options

You must be logged in to vote
1 reply
@gunters63
Comment options

Comment options

You must be logged in to vote
3 replies
@gunters63
Comment options

@haruhihi
Comment options

@tcodes0
Comment options

Comment options

You must be logged in to vote
2 replies
@xialvjun
Comment options

@Codigo-Fuentes
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@funkytek
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet