purchases-capacitor icon indicating copy to clipboard operation
purchases-capacitor copied to clipboard

Error: Failed to resolve entry for package "@revenuecat/purchases-capacitor" when running "vitest"

Open OkkioXavier opened this issue 10 months ago • 4 comments

Summary

When running vitest an error is thrown: Error: Failed to resolve entry for package "@revenuecat/purchases-capacitor". The package may have incorrect main/module/exports specified in its package.json.

This is blocking for us as it prevents our unit tests from succeeding in CI.

Version

10.0.2

Minimal Reproduction

Run npm run test.unit

https://github.com/OkkioXavier/revenue-cat-missing-main-target

Symptoms

When running npm run test.unit in the ionic example project with revenuecat configured I get the following error:

Error: Failed to resolve entry for package "@revenuecat/purchases-capacitor". The package may have incorrect main/module/exports specified in its package.json. ❯ packageEntryFailure node_modules/vite/dist/node/chunks/dep-p3C6MpSJ.js:49442:17 ❯ resolvePackageEntry node_modules/vite/dist/node/chunks/dep-p3C6MpSJ.js:49439:5 ❯ tryNodeResolve node_modules/vite/dist/node/chunks/dep-p3C6MpSJ.js:49209:20 ❯ Context.resolveId node_modules/vite/dist/node/chunks/dep-p3C6MpSJ.js:48959:28 ❯ Object.resolveId node_modules/vite/dist/node/chunks/dep-p3C6MpSJ.js:52242:32 ❯ TransformContext.resolve node_modules/vite/dist/node/chunks/dep-p3C6MpSJ.js:51933:23 ❯ normalizeUrl node_modules/vite/dist/node/chunks/dep-p3C6MpSJ.js:67301:34 ❯ async file:/***/revenue-cat-missing-main-target/myApp/node_modules/vite/dist/node/chunks/dep-p3C6MpSJ.js:67465:47

The only change I have made to the base template is to add the following lines to App.tsx

await Purchases.setLogLevel({level: LOG_LEVEL.DEBUG}); // Enable to get debug logs
await Purchases.configure({
  apiKey: '',
  appUserID: '' // Optional
})

Possible cause

The file "dist/plugin.cjs.js" does not exist in the package but is defined in package.json as the entry point in package.json

Modifying main from:

{
  "name": "@revenuecat/purchases-capacitor",
  "version": "10.0.2",
  "description": "Capacitor in-app purchases and subscriptions made easy. Support for iOS and Android.",
  "main": "dist/plugin.cjs.js",
  "module": "dist/esm/index.js",
  "types": "dist/esm/index.d.ts",
  "unpkg": "dist/plugin.js"
...
}

to

{
  "name": "@revenuecat/purchases-capacitor",
  "version": "10.0.2",
  "description": "Capacitor in-app purchases and subscriptions made easy. Support for iOS and Android.",
  "main": "dist/esm/index.js"
  "module": "dist/esm/index.js",
  "types": "dist/esm/index.d.ts",
  "unpkg": "dist/plugin.js"
}

gives me the expected error: Web not supported in this plugin.

OkkioXavier avatar Feb 15 '25 21:02 OkkioXavier

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

RCGitBot avatar Feb 15 '25 21:02 RCGitBot

I have the same problem, fixing the package.json works.

hedinasr avatar Feb 16 '25 09:02 hedinasr

Thanks for reporting this and for the minimal reproduction project. Our team is reviewing this.

Jethro87 avatar Feb 19 '25 18:02 Jethro87

Does this means unit test is not possible currently?

I want to migrate from another solution because their testing environment does not really work as it should and I really do not want to land in the same problem.

distante avatar Feb 26 '25 19:02 distante

I've just encountered this problem. Any solutions?

davidjmstewart avatar May 29 '25 03:05 davidjmstewart

@Jethro87 any update on this? It seems like a pretty trivial fix to push. It's currently breaking a number of our tests.

davidjmstewart avatar Jun 27 '25 01:06 davidjmstewart

@Jethro87 any update on this? It seems like a pretty trivial fix to push. It's currently breaking a number of our tests.

Thanks for the bump! I will look tomorrow to see what we can do about this 💪

joshdholtz avatar Jun 27 '25 01:06 joshdholtz