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

Module not found: Can't resolve 'ably' after upgrading to 2.0.3 #1751

Closed
Mosquid opened this issue Apr 25, 2024 · 10 comments · Fixed by #1782
Closed

Module not found: Can't resolve 'ably' after upgrading to 2.0.3 #1751

Mosquid opened this issue Apr 25, 2024 · 10 comments · Fixed by #1782
Assignees
Labels
bug Something isn't working. It's clear that this does need to be fixed. investigate

Comments

@Mosquid
Copy link

Mosquid commented Apr 25, 2024

I upgraded from 1.2.49 to 2.0.3 and the next time I started my react project, It gave me this error:

Module not found: Can't resolve 'ably' in '...'

┆Issue is synchronized with this Jira Task by Unito

@lawrence-forooghian
Copy link
Collaborator

Hi @Mosquid, thanks for your report. It’s hard to know what’s causing this from the information that you’ve provided.

My first question is whether you followed the v2 migration guide? I ask because you mention that you upgraded from 1.2.49. The first step of the migration guide is to upgrade to 1.2.50 before performing the upgrade to v2.

@Mosquid
Copy link
Author

Mosquid commented Apr 30, 2024

Hey. Here are the reproduction steps:

  • install ably@1.2.49
  • run yarn upgrade ably@^ and select 1.2.50
  • run yarn upgrade ably@^ and select 2.0.3
  • The compiler succeeded but the useChannel hook started giving me an error about the missing client.
  • I stopped, removed the node_modules and re-installed packages. After that the compiler won't start with Module not found: Can't resolve 'ably' in '...'

I'm using Node v18.16.0 and React 18.2.0

@VeskeR
Copy link
Contributor

VeskeR commented May 2, 2024

Hi @Mosquid !
Unfortunately, I couldn't reproduce the Module not found: Can't resolve 'ably' in '...' error following your steps with our ably-js nextjs example repo (specifically based on this commit as the latest commit in repo is already using ably-js v2).

After upgrading to ably-js v2 I only got expected errors, such as Package path ./promises is not exported from package and TypeError: ably__WEBPACK_IMPORTED_MODULE_1__.Realtime.Promise is not a constructor, due to changes to our exports configuration in ably-js v2. Required changes you need to do in the codebase when upgrading to ably-js v2 are covered in our v2 migration guide, and react-hooks v2 migration guide.

If you are still experiencing this problem, could you please share more information about your project setup that might affect dependency resolution (like your tsconfig.json) and code example of how are you trying to import and use Ably client and react hooks? Thank you!

@VeskeR
Copy link
Contributor

VeskeR commented May 17, 2024

Hello @Mosquid !

I hope you're doing well. Were you able to resolve your issue with installing ably using yarn?

@Mosquid
Copy link
Author

Mosquid commented May 17, 2024

Hi @VeskeR,
No, unfortunately not. Here is the code of my ably provider.

import { AblyProvider } from "ably/react";
import * as Ably from "ably";
import { FC } from "react";
import { observer } from "mobx-react";
import { ErrorInfo } from "ably";

const client = new Ably.Realtime({
  httpMaxRetryCount: 5,
  authCallback: async (_, callback) => {
    try {
      // custom auth
    } catch (error) {
      callback(error as ErrorInfo, null);
    }
  },
  authParams: {
    path: location.pathname,
  },
});

const AblyClientProvider: FC = ({ children }) => {
  return <AblyProvider client={client}>{children}</AblyProvider>;
};

export default observer(AblyClientProvider);

Error: Module not found: Can't resolve 'ably' in AblyClientProvider.tsx

@CurrrBell
Copy link

I have run into this as well, but only when running Jest tests. I've got v2.0.2 installed. Ably is new to my project, however, so I didn't do any migration from 1.x. I get the same error message that @Mosquid gets. Even if I try to mock it, Jest seems to have no idea what ably is.

This answer on Stack Overflow (although very old) mentions that the package the OP asked about had no main entry in its package.json. I found this to be the case for ably's package.json, whereas other packages in my dependencies do have a main. I'm very out of my depth here so forgive me if this is totally nonsensical, but this was the closest thing to a lead other than this GH issue that I could find for this.

@matthewcaminiti
Copy link

+1 Same issue here with 2.0.4, never migrated and am suffering with my build step due to lack of main entry

@sync-by-unito sync-by-unito bot added the bug Something isn't working. It's clear that this does need to be fixed. label May 28, 2024
@VeskeR
Copy link
Contributor

VeskeR commented May 29, 2024

@CurrrBell What version of the Jest are you using? It seems that Jest <28 was not able to resolve dependencies from exports field in installed packages, but it should've been fixed in Jest >=28.

@matthewcaminiti What does your environment look like in which you are trying to use ably package (e.g. are you using nodejs/deno/bun (also which version), npm/yarn/pnpm) ?

@matthewcaminiti
Copy link

@CurrrBell What version of the Jest are you using? It seems that Jest <28 was not able to resolve dependencies from exports field in installed packages, but it should've been fixed in Jest >=28.

@matthewcaminiti What does your environment look like in which you are trying to use ably package (e.g. are you using nodejs/deno/bun (also which version), npm/yarn/pnpm) ?

Hey sorry forgot about this thread, got things resolved on my setup with the Webpack suggestion in the readme (using metro bundler in Expo React Native monorepo)!

For context if still desired:
Node 20.11.1, npm 10.2.4

VeskeR added a commit that referenced this issue Jun 3, 2024
Those fields were removed in de5ddfa
and replaced with `exports` field we currently use. However, removal of
root level entry fields from `package.json` have caused issues with
importing `ably` in some setups:
- React Native wasn't able to resolve `ably` at all, due to `exports`
  field resolution is not enabled by default yet [1] (we fixed this by
  re-adding root level `react-native` field in #1713)
- older bundler versions do not support `exports` field, for example,
  webpack has added support for `exports` only in v5.
- TypeScript added support for resolving `exports` field only in its 4.7
  release [2]

This commit re-adds root level entry fields so those setups will still
be able to resolve `ably` package.

Resolves #1751

[1] https://reactnative.dev/blog/2023/06/21/package-exports-support
[2] https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#packagejson-exports-imports-and-self-referencing
VeskeR added a commit that referenced this issue Jun 3, 2024
Those fields were removed in de5ddfa
and replaced with `exports` field we currently use. However, removal of
root level entry fields from `package.json` have caused issues with
importing `ably` in some setups:
- React Native wasn't able to resolve `ably` at all, due to `exports`
  field resolution is not enabled by default yet [1] (we fixed this by
  re-adding root level `react-native` field in #1713)
- older bundler versions do not support `exports` field, for example,
  webpack has added support for `exports` only in v5.
- TypeScript added support for resolving `exports` field only in its 4.7
  release [2]

This commit re-adds root level entry fields so those setups will still
be able to resolve `ably` package.

Resolves #1751

[1] https://reactnative.dev/blog/2023/06/21/package-exports-support
[2] https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#packagejson-exports-imports-and-self-referencing
@VeskeR VeskeR reopened this Jun 3, 2024
@VeskeR
Copy link
Contributor

VeskeR commented Jun 3, 2024

Hi!
In 2.1.0 release of ably-js we have re-added the main and browser fields to the root level of package.json. This should fix the Can't resolve 'ably' error in environments/setups that can't correctly resolve the package based on the exports field from package.json. Please try that version out and let us know if you are experiencing any other issues.
Thank you for reporting this problem!

@VeskeR VeskeR closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. It's clear that this does need to be fixed. investigate
Development

Successfully merging a pull request may close this issue.

5 participants