algoliasearch-client-javascript
algoliasearch-client-javascript copied to clipboard
Consider using ECMAScript Modules
Could you consider using ECMAScript Modules ?
Warning is raised when compiling app with angular-instantsearch

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.
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 forumd
. Switching fromumd
toesm
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)
exports
has already been discussed here https://github.com/algolia/algoliasearch-client-javascript/issues/1381
An easy fix for the missing TS definition is to create this d.ts
file anywhere in your project
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