posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

Cannot find module and when installing dependency it doesnt compile

Open raquelsrocha opened this issue 1 year ago • 12 comments

Bug Description

A few months ago i was able to add posthog to my Angular project and even had it recording sessions and such. This was just experimental so i didn't even merge the changes (just had them locally). Now i tried to run it and it complained about not finding rrweb/record module. I installed it and then it doesn't compile due to errors in rrdom. The only (main) difference was that i did some minor/patch updates in the whole project. So i decided to create a blank stackblitz to check if this would still happen and it did (described below).

How to reproduce

  • Stackblitz with Angular base project with just "posthog-js" added : https://stackblitz.com/edit/stackblitz-starters-dgyh5r?file=package.json
  • Run "npm install && npm start"
  • You will get the error "Cannot find module" regarding @rrweb/record and @rrweb/types
  • If you install both (as dev dependencies) then you get "cannot find "errors in rrdom/dist and rrweb/dist files.

Note: The only file besides package.json changed, was maint.ts to import posthog.

raquelsrocha avatar Nov 18 '24 12:11 raquelsrocha

I also got same issue when I try to use latest version of posthog in my angular project.

da201501245 avatar Nov 22 '24 17:11 da201501245

Same, I am also getting the same errors, I will have to revert back until this gets fixed.

migueldv90 avatar Nov 22 '24 17:11 migueldv90

Almost every release of posthog breaks my Angular build. This one is not an exception.

vvolodin avatar Nov 22 '24 18:11 vvolodin

This is the second time my posthog-js has broken my angular app, I also had issues with the go lang package as well.

migueldv90 avatar Nov 23 '24 07:11 migueldv90

Is there any workaround for this?

jer-tx avatar Nov 24 '24 21:11 jer-tx

I totally agree and can confirm that this is not an exception.

Some try & error later I was able to find a dependency combination which seem to work.

npm install [email protected] --save-dev
npm install @rrweb/[email protected]  --save-dev
npm install [email protected]

Keeping Posthog's dependencies in own package.json is a absolute no-go and will cause more issues in future. This must be fixed.

Hope this helps, @jer-tx

Synatiic avatar Nov 25 '24 17:11 Synatiic

I totally agree and can confirm that this is not an exception.

Some try & error later I was able to find a dependency combination which seem to work.

npm install [email protected] --save-dev
npm install @rrweb/[email protected]  --save-dev
npm install [email protected]

Keeping Posthog's dependencies in own package.json is a absolute no-go and will cause more issues in future. This must be fixed.

Hope this helps, @jer-tx

It helped me, thanks! Will use these specific versions for now.

raquelsrocha avatar Nov 26 '24 10:11 raquelsrocha

Based on some initial research, this issue appears have been introduced in this PR: v1.163.1 doesn't have this type issue, whereas v1.164.0 does.

As an alternative workaround, users may want to consider downgrading to v1.163.1 until this is fixed.

jonnyarnold avatar Dec 04 '24 08:12 jonnyarnold

I totally agree and can confirm that this is not an exception.

Some try & error later I was able to find a dependency combination which seem to work.

npm install [email protected] --save-dev
npm install @rrweb/[email protected]  --save-dev
npm install [email protected]

Keeping Posthog's dependencies in own package.json is a absolute no-go and will cause more issues in future. This must be fixed.

Hope this helps, @jer-tx

It worked for me too. Thanks.

Roodaka avatar Dec 10 '24 12:12 Roodaka

Same error, will it be fixed?

VladislavLobakh avatar Jan 30 '25 16:01 VladislavLobakh

Tried installing posthog 1.215.1

I import it like this:

import posthog from 'posthog-js/dist/module.full.no-external'

It says this when building it:

[ng] Error: node_modules/posthog-js/dist/module.full.no-external.d.ts:1:31 - error TS2307: Cannot find module '@rrweb/types' or its corresponding type declarations.
[ng] 1 import { eventWithTime } from '@rrweb/types';
[ng]                                 ~~~~~~~~~~~~~~
[ng] Error: node_modules/posthog-js/dist/module.full.no-external.d.ts:2:24 - error TS2307: Cannot find module '@rrweb/record' or its corresponding type declarations.
[ng] 2 import { record } from '@rrweb/record';
[ng]                          ~~~~~~~~~~~~~~~

My env:

node 23.7.0
typescript 5.5.4

I tried with node v22.13.1 too. But got the same results.

Tried installing the missing dependencies with the same version as specified in the posthog-js/package.json for this version.

        "@rrweb/record": "2.0.0-alpha.17",
        "@rrweb/types": "2.0.0-alpha.17",

Then I get the following errors:

[ng]   node_modules/@rrweb/types/dist/index.d.ts:1:10
[ng]     1 import { DataURLOptions } from 'rrweb-snapshot';
[ng]                ~~~~~~~~~~~~~~
[ng]     'DataURLOptions' is declared here.
[ng] Error: node_modules/rrweb-snapshot/dist/index.d.ts:2:10 - error TS2305: Module '"@rrweb/types"' has no exported member 'IMirror'.
[ng] 2 import { IMirror } from '@rrweb/types';
[ng]            ~~~~~~~
[ng] Error: node_modules/rrweb-snapshot/dist/index.d.ts:3:10 - error TS2305: Module '"@rrweb/types"' has no exported member 'serializedElementNodeWithId'.
[ng] 3 import { serializedElementNodeWithId } from '@rrweb/types';
[ng]            ~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/rrweb-snapshot/dist/index.d.ts:4:10 - error TS2305: Module '"@rrweb/types"' has no exported member 'serializedNode'.
[ng] 4 import { serializedNode } from '@rrweb/types';
[ng]            ~~~~~~~~~~~~~~
[ng] Error: node_modules/rrweb-snapshot/dist/index.d.ts:5:10 - error TS2459: Module '"@rrweb/types"' declares 'serializedNodeWithId' locally, but it is not exported.
[ng] 5 import { serializedNodeWithId } from '@rrweb/types';
[ng]            ~~~~~~~~~~~~~~~~~~~~
[ng]   node_modules/@rrweb/types/dist/index.d.ts:4:10
[ng]     4 import { serializedNodeWithId } from 'rrweb-snapshot';
[ng]                ~~~~~~~~~~~~~~~~~~~~
[ng]     'serializedNodeWithId' is declared here.
[ng] Error: node_modules/rrweb/dist/rrweb.d.ts:216:25 - error TS2395: Individual declarations in merged declaration 'record' must be all exported or all local.
[ng] 216 export declare function record<T = eventWithTime>(options?: recordOptions<T>): listenerHandler | undefined;
[ng]                             ~~~~~~
[ng] Error: node_modules/rrweb/dist/rrweb.d.ts:218:26 - error TS2395: Individual declarations in merged declaration 'record' must be all exported or all local.
[ng] 218 export declare namespace record {
[ng]                              ~~~~~~
[ng] Error: node_modules/rrweb/dist/rrweb.d.ts:468:19 - error TS2395: Individual declarations in merged declaration 'record' must be all exported or all local.
[ng] 468 declare namespace record {
[ng]                       ~~~~~~

After digging deeper I feel this issue has something to do with the fact that @rrweb/record is patched from pnpm. https://github.com/PostHog/posthog-js/blob/main/patches/%40rrweb__record%402.0.0-alpha.17.patch

Please help us update to the latest posthog.

The only working solution I found...

npm install [email protected] --save-dev npm install @rrweb/[email protected] --save-dev npm install [email protected]

But this requires us to lock versions to way older versions. ☹ Please advise on how to proceed if we want to use the latest version. Thank you!

EDIT: I moved this comment here from another thread at #1437 . I felt it is more relevant here.

tbence94 avatar Feb 03 '25 14:02 tbence94

@PostHog/team-replay

marandaneto avatar Oct 06 '25 11:10 marandaneto