algolia / algoliasearch-client-javascript

⚡️ A fully-featured and blazing-fast JavaScript API client to interact with Algolia.
https://www.algolia.com/doc/api-client/javascript/getting-started/
MIT License
1.33k stars 222 forks source link

algoliasearch v5 not building in a typescript project #1538

Closed OutdatedGuy closed 2 weeks ago

OutdatedGuy commented 3 weeks ago

Steps to reproduce:

  1. Create a typescript project (preferably a firebase cloud function project)
  2. Add algoliasearch with below command
    npm install algoliasearch@5
  3. Build the project using tsc command
  4. See below error

    > tsc
    
    node_modules/algoliasearch/dist/algoliasearch/builds/node.d.ts:2:48 - error TS2307: Cannot find module '@algolia/client-abtesting/src/abtestingClient' or its corresponding type declarations.
    
    2 import type { Region as AbtestingRegion } from '@algolia/client-abtesting/src/abtestingClient';
                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    node_modules/algoliasearch/dist/algoliasearch/builds/node.d.ts:4:48 - error TS2307: Cannot find module '@algolia/client-analytics/src/analyticsClient' or its corresponding type declarations.
    
    4 import type { Region as AnalyticsRegion } from '@algolia/client-analytics/src/analyticsClient';
                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    node_modules/algoliasearch/dist/algoliasearch/builds/node.d.ts:7:54 - error TS2307: Cannot find module '@algolia/client-personalization/src/personalizationClient' or its corresponding type declarations.
    
    7 import type { Region as PersonalizationRegion } from '@algolia/client-personalization/src/personalizationClient';
                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    Found 3 errors in the same file, starting at: node_modules/algoliasearch/dist/algoliasearch/builds/node.d.ts:2

Things Already Tried

shortcuts commented 3 weeks ago

Hey @OutdatedGuy thanks for trying out the v5 client

I've not been able to reproduce the error, it compiles correctly on my side.

However from the error you shared, it seems like the peer dependencies of algoliasearch are not installed. If they do not resolve automatically for you, it might be an exports issue on our side.

Was it working with v4? You can also try to install them manually (@algolia/client-personalization and so on), or use the umd bundled file which contains them, usually for the browser env import {algoliasearch} from "algoliasearch/dist/algoliasearch.umd.js"

OutdatedGuy commented 3 weeks ago

@shortcuts

Was it working with v4?

Yes. On v4 it was working flawlessly but since v5 I cannot build my project :(

You can also try to install them manually (@algolia/client-personalization and so on)

I installed the dependencies mentioned in the error logs with:

npm install @algolia/client-personalization @algolia/client-analytics @algolia/client-abtesting;

but still the same error occurs.

e-compa commented 2 weeks ago

Hi,

we've encountered the same error, and we were able to work around it by modifying _node_modules/.pnpm/algoliasearch@5.1.1/nodemodules/algoliasearch/dist/algoliasearch/builds/node.d.ts

from this:

import type { AbtestingClient } from '@algolia/client-abtesting';
import type { Region as AbtestingRegion } from '@algolia/client-abtesting/src/abtestingClient';
import type { AnalyticsClient } from '@algolia/client-analytics';
import type { Region as AnalyticsRegion } from '@algolia/client-analytics/src/analyticsClient';
import type { ClientOptions } from '@algolia/client-common';
import type { PersonalizationClient } from '@algolia/client-personalization';
import type { Region as PersonalizationRegion } from '@algolia/client-personalization/src/personalizationClient';
import type { RecommendClient } from '@algolia/recommend';
import type { InitClientOptions, InitClientRegion, GenerateSecuredApiKeyOptions, GetSecuredApiKeyRemainingValidityOptions } from './models';
export * from './models';
export declare const apiClientVersion = "5.1.1";

to this:

import type { AbtestingClient } from '@algolia/client-abtesting';
import type { Region as AbtestingRegion } from '@algolia/client-abtesting/dist/src/abtestingClient';
import type { AnalyticsClient } from '@algolia/client-analytics';
import type { Region as AnalyticsRegion } from '@algolia/client-analytics/dist/src/analyticsClient';
import type { ClientOptions } from '@algolia/client-common';
import type { PersonalizationClient } from '@algolia/client-personalization';
import type { Region as PersonalizationRegion } from '@algolia/client-personalization/dist/src/personalizationClient';
import type { RecommendClient } from '@algolia/recommend';
import type { InitClientOptions, InitClientRegion, GenerateSecuredApiKeyOptions, GetSecuredApiKeyRemainingValidityOptions } from './models';
export * from './models';
export declare const apiClientVersion = "5.1.1";

since the import path does not match the folder structure

zapobyte commented 2 weeks ago

I have also managed to reproduce this using version "5.1.1".

shortcuts commented 2 weeks ago

Hey there, thanks for providing more context to the issue!

Could you please let me know if the latest version fixes the issue on your side?

OutdatedGuy commented 2 weeks ago

@shortcuts I tried with the latest version (5.2.1) but having the same issue. So I looked into the error file and saw imports whose paths don't exist (@algolia/client-abtesting/src/abtestingClient). So I just updated code to import from base package and it worked.

Basically:

- import type { AbtestingClient } from '@algolia/client-abtesting';
- import type { Region as AbtestingRegion } from '@algolia/client-abtesting/src/abtestingClient';
+ import type { AbtestingClient, Region as AbtestingRegion } from '@algolia/client-abtesting';

Can you re-open the issue?

shortcuts commented 2 weeks ago

@shortcuts I tried with the latest version (5.2.1) but having the same issue. So I looked into the error file and saw imports whose paths don't exist (@algolia/client-abtesting/src/abtestingClient). So I just updated code to import from base package and it worked.

Basically:

- import type { AbtestingClient } from '@algolia/client-abtesting';
- import type { Region as AbtestingRegion } from '@algolia/client-abtesting/src/abtestingClient';
+ import type { AbtestingClient, Region as AbtestingRegion } from '@algolia/client-abtesting';

Can you re-open the issue?

Hey, thanks for testing it! it was fixed in 5.2.2, could you retry please?

OutdatedGuy commented 2 weeks ago

Hi, I tried 5.2.2 and it worked. Thanks.

shortcuts commented 2 weeks ago

Lets goooo enjoy!! Thanks you