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

[bug]: Could not find a declaration file for module '@algolia/client-search' in v5.2.2 #1544

Closed
kasperaamodt opened this issue Aug 29, 2024 · 20 comments · Fixed by algolia/api-clients-automation#3640
Labels

Comments

@kasperaamodt
Copy link

Description

Seems like the the issue of types not being included is back in v5.2.2. When I downgrade to 5.1.1, they are included.

Client

All

Version

5.2.2.

Relevant log output

No response

@shortcuts
Copy link
Member

Hey, thanks for reporting the issue! Could you please let me know which env (node or browser)?

@wKovacs64
Copy link

Types for algoliasearch/lite are gone too, typecheck failed in CI for me. May want to check out https://arethetypeswrong.github.io if you haven't already. Doesn't look like they were quite right™️ in 5.2.1 either but they were more right, I guess. 🙂

5.2.1: https://arethetypeswrong.github.io/?p=algoliasearch%405.2.1
5.2.2: https://arethetypeswrong.github.io/?p=algoliasearch%405.2.2

@shortcuts
Copy link
Member

Huge, thanks for the suggestion, I didn't knew that website. Bundling for node and browser is so complicated, sorry for the issues.

I think I know why types are gone but it should resolve the ones from node/browser instead 🤔

@karlhorky
Copy link

karlhorky commented Aug 30, 2024

[email protected] is unable to resolve the main algoliasearch import specifier in bundlers:

> tsdx build --format esm --target node --tsconfig tsconfig.src.json

⠼ Building modules
(typescript) Error: src/checks/noDependencyProblems/noDependenciesWithoutTypes.ts:2:31 - error TS2307: Cannot find module 'algoliasearch' or its corresponding type declarations.

2 import { algoliasearch } from 'algoliasearch';
                                ~~~~~~~~~~~~~~~

Screenshot 2024-08-30 at 11 15 21

@dstroot
Copy link

dstroot commented Aug 31, 2024

import { liteClient } from 'algoliasearch/lite'

No longer works with 5.2.3, works with 5.1.1. Node v20.17.0. Had to roll back algolia search update. :(

ps - typescript project.

@Zach-Jaensch
Copy link

Hey team! We just attempted to upgrade to 5.2.3 today and ran into the same issue.

I think I know why types are gone but it should resolve the ones from node/browser instead 🤔

It looks like you have found the cause of the issue, but as to why it breaks, it's not always determinable ahead of time if code is browser or node only (react server components or Nextjs for example)

It looks like node recommends to use "node" and "default" over "node" and "browser" for this reason.
https://nodejs.org/api/packages.html#:~:text=When%20using%20environment,browser%22%20condition%20branches.

We had attempted to implement a pnpm patch for this, but ran into some CI/CD build issues stopping us, although changing browser back to default did solve our issue.

@shortcuts
Copy link
Member

Hey @Zach-Jaensch sorry for the issues, algolia/api-clients-automation#3640 have everything fixed up, I'll try to ship that today

@Zach-Jaensch
Copy link

Amazing. Will try it out in the morning and let you know!

@dstroot
Copy link

dstroot commented Sep 2, 2024

Still seeing a problem with 5.2.4 - forgot to mention I am using pnpm 9.9.0 too.

▲ Next.js 14.2.7
  - Environments: .env.local
  - Experiments (use with caution):
    · turbo
    · webpackBuildWorker

   Creating an optimized production build ...
 ✓ Compiled successfully
   Linting and checking validity of types  ..Failed to compile.

./src/components/search/Search.tsx:3:28
Type error: Cannot find module 'algoliasearch/lite' or its corresponding type declarations.

  1 | 'use client'
  2 |
> 3 | import { liteClient } from 'algoliasearch/lite'
    |                            ^
  4 | import { InstantSearch, useInstantSearch } from 'react-instantsearch'
  5 |
  6 | import { env } from '@/config/env.mjs'
 ELIFECYCLE  Command failed with exit code 1.

@shortcuts
Copy link
Member

Hey, yup nothing has changed in 5.2.4, algolia/api-clients-automation#3640 is not yet merged

@shortcuts
Copy link
Member

Hey there, I just released a 5.2.4-beta.2 version with a fix for this issue, if you have time, please try it out and let me know so I can go ahead with the PR :)

Thanks

@dstroot
Copy link

dstroot commented Sep 2, 2024

@shortcuts Yay! It works again > [email protected]. Happy Labor Day! :)

@shortcuts
Copy link
Member

leeeeetsss goooooooooooo!!

this will be released in stable tomorrow, happy labor day :)

@Zach-Jaensch
Copy link

Can confirm 5.2.4-beta.2 works for us as well.
It also fixed another issue with the types from "algoliasearch" not resolving correctly for the search client!
Looking forward to the stable release.

Thanks for the fix!

@Zach-Jaensch
Copy link

Sorry to bring more issues (can create a new issue if it is too unrelated) there appears to be missing type exports from the subdeps of algoliasearch. Here is the output of our nextjs app, and a minimum repo (vite react) to help with testing.

Failed to compile.

../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
Attempted import error: 'Region' is not exported from '@algolia/client-abtesting' (imported as 'ABTestingRegion').

Import trace for requested module:
../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
./src/utils/algolia/client.ts
./src/utils/algolia/search.ts

../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
Attempted import error: 'AbtestingClient' is not exported from '@algolia/client-abtesting' (imported as 'AbtestingClient').

Import trace for requested module:
../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
./src/utils/algolia/client.ts
./src/utils/algolia/search.ts

../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
Attempted import error: 'AdvancedSyntaxFeatures' is not exported from '@algolia/client-search' (imported as 'AdvancedSyntaxFeatures').

Import trace for requested module:
../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
./src/utils/algolia/client.ts
./src/utils/algolia/search.ts

../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
Attempted import error: 'AlternativesAsExact' is not exported from '@algolia/client-search' (imported as 'AlternativesAsExact').

Import trace for requested module:
../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
./src/utils/algolia/client.ts
./src/utils/algolia/search.ts

../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
Attempted import error: 'AnalyticsClient' is not exported from '@algolia/client-analytics' (imported as 'AnalyticsClient').

Import trace for requested module:
../../node_modules/.pnpm/[email protected]/node_modules/algoliasearch/dist/browser.js
./src/utils/algolia/client.ts
./src/utils/algolia/search.ts


> Build failed because of webpack errors

https://github.com/Zach-Jaensch/algoliasearch-build-issue

@shortcuts
Copy link
Member

ngl your 2 comments were an emotional rollercoaster @Zach-Jaensch................

but it's fixed in -beta.6 :D

@shortcuts
Copy link
Member

The fix has been released in 5.2.5!

@karlhorky
Copy link

@shortcuts thanks!

I can confirm that [email protected] has now resolved the algolia package resolution problems

Are The Types Wrong? also reports successful checks for [email protected]:

Screenshot 2024-09-05 at 13 19 06

@shortcuts
Copy link
Member

Thanks for testing!! I've also integrated attw and publint to our CI so we can make sure not to introduce regressions :D

@Zach-Jaensch
Copy link

Zach-Jaensch commented Sep 10, 2024

Sorry for the delay (had a busy week come out of nowhere), it works fine for us now.
Thanks for getting the types all fix up, rollercoaster and all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants