Error: Failed to resolve entry for package "@revenuecat/purchases-capacitor" when running "vitest"
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.
👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!
I have the same problem, fixing the package.json works.
Thanks for reporting this and for the minimal reproduction project. Our team is reviewing this.
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.
I've just encountered this problem. Any solutions?
@Jethro87 any update on this? It seems like a pretty trivial fix to push. It's currently breaking a number of our tests.
@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 💪