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

algoliasearch v5 not building in a typescript project #1538

Closed
OutdatedGuy opened this issue Aug 16, 2024 · 14 comments · Fixed by algolia/api-clients-automation#3596
Closed
Labels
more info needed v5 Anything new v5 major related

Comments

@OutdatedGuy
Copy link

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

  • Updating/installing packages using npm install and npm update
  • Deleting node_modules dir and reinstalling npm pacages
  • Clearing all caches and reinstalling and building project
@shortcuts shortcuts added v5 Anything new v5 major related more info needed labels Aug 16, 2024
@shortcuts
Copy link
Member

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
Copy link
Author

@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
Copy link

e-compa commented Aug 23, 2024

Hi,

we've encountered the same error, and we were able to work around it by modifying node_modules/.pnpm/[email protected]/node_modules/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
Copy link

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

  • Some additional info if it matters, I'm on a Windows machine.

@shortcuts
Copy link
Member

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
Copy link
Author

OutdatedGuy commented Aug 29, 2024

@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
Copy link
Member

@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
Copy link
Author

Hi, I tried 5.2.2 and it worked. Thanks.

@shortcuts
Copy link
Member

Lets goooo enjoy!! Thanks you

@valeriangalliat
Copy link

Encountering the same issue with [email protected]

../../node_modules/@algolia/client-common/src/transporter/helpers.ts(12,5): error TS2322: Type 'TData | undefined' is not assignable to type 'TData'.
  'TData' could be instantiated with an arbitrary type which could be unrelated to 'TData | undefined'.
../../node_modules/@algolia/client-common/src/transporter/helpers.ts(13,5): error TS2322: Type 'TData | undefined' is not assignable to type 'TData'.
  'TData' could be instantiated with an arbitrary type which could be unrelated to 'TData | undefined'.
../../node_modules/@algolia/client-common/src/transporter/helpers.ts(72,5): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.
husky - pre-commit hook exited with code 1 (error)

It seems TypeScript (5.5.4 but also tried with 5.6.2 (latest)) doesn't respect the package.json exports field and still reads node_modules/@algolia/client-common/index.ts and its subtree from src/ instead of the dist/ files.

Removing node_modules/@algolia/client-common/index.ts solves the issue

@Mandy9943
Copy link

Same problem as above here
image

Im using ^5.7.0

@shortcuts
Copy link
Member

hey @Mandy9943 @valeriangalliat it seems related to #1561, which should be fixed with algolia/api-clients-automation#3966

@HemalR
Copy link

HemalR commented Oct 20, 2024

I think I am getting the same (or a similar) error:

No matching export in "node_modules/@algolia/client-abtesting/dist/builds/browser.js" for import "Status"

I can see that all the dependencies of algoliasearch (V 5.9.1) are installed.

image

Not sure how to fix or what to try. Open to suggestions. (Please let me know if I should create a new issue for this).

Edit to add link to reproduction of bug:

https://stackblitz.com/edit/sveltejs-kit-template-default-qmp5ae?file=src%2Froutes%2F%2Bpage.svelte

@sureshkumarsendrayan
Copy link

@5.7.0

I'm also facing the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed v5 Anything new v5 major related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants