Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using ECMAScript Modules #1437

Open
thiboot opened this issue Jan 20, 2023 · 3 comments
Open

Consider using ECMAScript Modules #1437

thiboot opened this issue Jan 20, 2023 · 3 comments

Comments

@thiboot
Copy link

thiboot commented Jan 20, 2023

Could you consider using ECMAScript Modules ?

Warning is raised when compiling app with angular-instantsearch

Screenshot 2023-01-21 at 14 07 47

From angular documentation :

It is recommended that you avoid depending on CommonJS modules in your Angular applications. Depending on CommonJS modules can prevent bundlers and minifiers from optimizing your application, which results in larger bundle sizes. Instead, it is recommended that you use ECMAScript modules in your entire application. For more information, see How CommonJS is making your bundles larger.

@GabrielDelepine
Copy link

the NPM package does contain ECMAScript Modules files

dist/algoliasearch-lite.esm.browser.js
algoliasearch.esm.browser.js

But these files are not referenced in the package.json. I see different reasons for that :

  • The field module is not supporting multi-entry (as far as I know) and using it wouldn't be standard because the module field is not official
  • The browser field is already in use for umd. Switching from umd to esm files would be a breaking change

To fix this issue, an exports field listing all files present in the npm package need to be added to the package.json (not listing all files, including package.json itself, would be a breaking change, requiring bumping the major version)

If you need a fix right now, just import the ESM files directly in your app (side effect: Typescript won't be able to type the default export)

Screenshot 2023-02-15 at 16 19 39

Screenshot 2023-02-15 at 16 23 39

@GabrielDelepine
Copy link

exports has already been discussed here #1381

@GabrielDelepine
Copy link

GabrielDelepine commented Feb 16, 2023

An easy fix for the missing TS definition is to create this d.ts file anywhere in your project

Screenshot 2023-02-16 at 12 04 09

declare module 'algoliasearch/dist/algoliasearch-lite.esm.browser.js' {
  export * from 'algoliasearch/dist/algoliasearch-lite';
  export { default } from 'algoliasearch/dist/algoliasearch-lite';
}

PS: In order to create a PR, I had a look at the scripts/build.js and rollup.config.js files in this repo but there are simply too many packages generated. It will be safer if a regular maintainer had a look at it

PS2: The name of the d.ts file can be anything. Only the .d.ts extension is mandatory

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

No branches or pull requests

2 participants