PostHog / posthog-js-lite

Reimplementation of posthog-js to be as light and modular as possible.
https://posthog.com/docs/libraries
MIT License
70 stars 36 forks source link

RN: expo-file-system could not be found within the project or in these directories (posthog-react-native >= 2.10.2) #164

Closed leeseonghyun21 closed 10 months ago

leeseonghyun21 commented 10 months ago

Bug description

In a bare React Native app environment, the following error occurs during Metro bundling when only using @react-native-async-storage/async-storage. This issue occurs in a non-Web environment and when expo-file-system is not installed.

BUNDLE  ./index.js

error: Error: Unable to resolve module expo-file-system from /Users/dev/sample-project-name/node_modules/posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoFileSystem.js: expo-file-system could not be found within the project or in these directories:
  node_modules
  ../node_modules
  ../../node_modules
> 1 | "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.OptionalExpoFileSystem=void 0;var _reactNative=require("react-native");var OptionalExpoFileSystem=undefined;exports.OptionalExpoFileSystem=OptionalExpoFileSystem;try{if(_reactNative.Platform.OS!=='web'){exports.OptionalExpoFileSystem=OptionalExpoFileSystem=require('expo-file-system');}}catch(e){}
    |                                                                                                                                                                                                                                                                                                                                                         ^
    at ModuleResolver.resolveDependency (/Users/dev/sample-project-name/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:153:15)
    at DependencyGraph.resolveDependency (/Users/dev/sample-project-name/node_modules/metro/src/node-haste/DependencyGraph.js:271:43)
    at /Users/dev/sample-project-name/node_modules/metro/src/lib/transformHelpers.js:176:21
    at resolveDependencies (/Users/dev/sample-project-name/node_modules/metro/src/DeltaBundler/buildSubgraph.js:56:25)
    at visit (/Users/dev/sample-project-name/node_modules/metro/src/DeltaBundler/buildSubgraph.js:107:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 8)
    at async visit (/Users/dev/sample-project-name/node_modules/metro/src/DeltaBundler/buildSubgraph.js:116:5)
    at async Promise.all (index 12)
    at async visit (/Users/dev/sample-project-name/node_modules/metro/src/DeltaBundler/buildSubgraph.js:116:5)

The operating environment is as follows.

System:
  OS: macOS 14.2.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 235.34 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.16.0
  Yarn:
    version: 4.0.2
  npm:
    version: 9.5.1
  Watchman:
    version: 2023.12.04.00
Managers:
  CocoaPods:
    version: 1.14.3
Languages:
  Java:
    version: 17.0.10
  Ruby:
    version: 3.3.0
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.2
    wanted: 0.73.2
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

How to reproduce

  1. Install posthog-react-native version 2.10.2 or higher in any React Native project.
  2. Build and run.

Related sub-libraries

Additional context

Thank you for your bug report – we love squashing them!

marandaneto commented 10 months ago

@leeseonghyun21 https://github.com/PostHog/posthog-js-lite/pull/166 should fix the issue, can you test it? thanks for the issue and PR.

kentandersen commented 10 months ago

This is still an issue with v2.11.1

leeseonghyun21 commented 10 months ago

@leeseonghyun21 #166 should fix the issue, can you test it? thanks for the issue and PR.

Thank you. I have confirmed that the bug reported in the newly released version 2.11.1 has been resolved. Thank you for your prompt response.

marandaneto commented 10 months ago

This is still an issue with v2.11.1

can you clean the cache and upgrade/recompile? our sample seems to be working and @leeseonghyun21 confirmed as well.

kentandersen commented 10 months ago

After double and trippelchecking caches and buildpipeline; I can confirm the issue is fixed with 2.11.1. Sorry for bad intel 🥺