juliencrn / usehooks-ts

React hook library, ready to use, written in Typescript.
https://usehooks-ts.com
MIT License
6.39k stars 416 forks source link

Rollup reports circular dependency errors #310

Closed jmc420 closed 8 months ago

jmc420 commented 1 year ago

Rollup is reporting these errors when bundling usehooks-ts

rollup v3.19.1
(!) Circular dependencies
node_modules/usehooks-ts/dist/esm/index.js -> node_modules/usehooks-ts/dist/esm/useClickAnyWhere/useClickAnyWhere.js -> node_modules/usehooks-ts/dist/esm/index.js
node_modules/usehooks-ts/dist/esm/index.js -> node_modules/usehooks-ts/dist/esm/useCountdown/useCountdown.js -> node_modules/usehooks-ts/dist/esm/index.js
node_modules/usehooks-ts/dist/esm/index.js -> node_modules/usehooks-ts/dist/esm/useDarkMode/useDarkMode.js -> node_modules/usehooks-ts/dist/esm/index.js
...and 16 more
(!) "this" has been rewritten to "undefined"
https://rollupjs.org/troubleshooting/#error-this-is-undefined
node_modules/usehooks-ts/dist/esm/useCopyToClipboard/useCopyToClipboard.js
1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
                    ^
2:     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3:     return new (P || (P = Promise))(function (resolve, reject) {
...and 1 other occurrence
node_modules/usehooks-ts/dist/esm/useFetch/useFetch.js
1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
                    ^
2:     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3:     return new (P || (P = Promise))(function (resolve, reject) {
...and 1 other occurrence
PSoltes commented 1 year ago

seconding this circulardeps

juliencrn commented 9 months ago

Please could you provide a minimal reproduction of your problem?

juliencrn commented 8 months ago

Hi all,

This error message reveals two different issues

The first part is due to the circular dependencies indeed, and it should be fixed by #440

rollup v3.19.1
(!) Circular dependencies
node_modules/usehooks-ts/dist/esm/index.js -> node_modules/usehooks-ts/dist/esm/useClickAnyWhere/useClickAnyWhere.js -> node_modules/usehooks-ts/dist/esm/index.js
node_modules/usehooks-ts/dist/esm/index.js -> node_modules/usehooks-ts/dist/esm/useCountdown/useCountdown.js -> node_modules/usehooks-ts/dist/esm/index.js
node_modules/usehooks-ts/dist/esm/index.js -> node_modules/usehooks-ts/dist/esm/useDarkMode/useDarkMode.js -> node_modules/usehooks-ts/dist/esm/index.js
...and 16 more

The next part is due to an incorrect ESM setup. It can't be fixed right now without introducing breaking changes but will be for sure in the incoming v3, ESM-first major release.

(!) "this" has been rewritten to "undefined"
https://rollupjs.org/troubleshooting/#error-this-is-undefined
node_modules/usehooks-ts/dist/esm/useCopyToClipboard/useCopyToClipboard.js
1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
                    ^
2:     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3:     return new (P || (P = Promise))(function (resolve, reject) {
...and 1 other occurrence
node_modules/usehooks-ts/dist/esm/useFetch/useFetch.js
1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
                    ^
2:     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3:     return new (P || (P = Promise))(function (resolve, reject) {
...and 1 other occurrence