Skip to content

Conversation

@dword-design
Copy link

I got this error the last time I used the lib in a project:

Cannot find module 'regenerator-runtime/runtime' Require stack: - <project>/node_modules/fetch-paginate/dist/main.js

So I decided to clean up the build and to migrate to ESM.

src/index.ts Outdated
);

const defaultParse = <$Body>(response: Response): Promise<$Body> =>
const defaultParse = (response: Response): Promise<any> =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dword-design what was the reason to remove these types?

Copy link
Author

@dword-design dword-design Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reason was that the typing in the current TypeScript reason leads to errors. response.json() returns just any (but which is not optimal imho), and response.text() returns a string. The problem is that response.text() contradicts with $Body. If that special handling wouldn't be there, Promise<$Body> would work. Setting Promise<$Body | string> leads to TypeScript errors when building.

Setting it to Promise<any> is not good though, so better have the types clean.

"scripts": {
"test": "jest",
"build": "webpack && tsc",
"build": "tsc",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dword-design thanks for the contribution! We're able to remove Webpack because we no longer need to transpile now that we're on ESM?

Copy link
Author

@dword-design dword-design Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I'd say Node.js runs right away and for the browser it should be possible to either use a bundler for the end-user project or import ESM. I tried it for defaults which only has an ESM export (and 29M downloads) and it works:

<!-- index.html -->

<script type="module">
import defaults from "https://esm.sh/defaults";

console.log(defaults({ a: 2 }, { a: 1, b: 2 }));
</script>

@@ -1,2 +0,0 @@
declare module 'parse-link-header';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dword-design what's the reason this type isn't needed anymore?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need it? It's imported in src/index.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants