Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-1384

Find solution for starting from a clean state when calling `npm prepare`/`pack` for packages

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      Historically, we call rm -rf dist as part of npm prepare in packages to ensure we start the npm pack from a clean state: https://github.com/realm/realm-js/blob/14adbee0f225eac0974c0a3286a0436f5c314cb1/packages/realm-network-transport/package.json#L18

      When updating the React Native integration tests to correctly pull in realm-network-transport as a localDependency https://github.com/realm/realm-js/blob/master/integration-tests/environments/react-native/package.json#L55, we hit an issue when running npx lerna bootstrap from the top level realm-js directory:

      1. The dist/bundle.d.ts for realm-network-transport is being created when realm-network-transport is first built during the boostrap process
      2. Subsequently, npm_config_legacy_peer_deps=true npm_config_ignore_scripts=true install-local is run for the React Native integration tests, which in turn calls npm pack, which in turn calls npm prepare for realm-network-transport
      3. npm prepare deletes the dist directory then runs build, but for some reason, bundle.d.ts in not present in the dist at the point where pack in being called
      lerna info lifecycle realm-react-native-tests@0.0.1~prepare: realm-react-native-tests@0.0.1
      
      > realm-react-native-tests@0.0.1 prepare /Users/tom.duncalf/dev/realm-js/integration-tests/environments/react-native
      > npm run install-local && pod-install
      
      
      > realm-react-native-tests@0.0.1 install-local
      > npm_config_legacy_peer_deps=true npm_config_ignore_scripts=true install-local
      
      [install-local] packing - 0/4Error: Command failed with exit code 2: npm pack /Users/tom.duncalf/dev/realm-js/integration-tests/tests
      npm ERR! code 2
      npm ERR! path /Users/tom.duncalf/dev/realm-js/integration-tests/tests
      npm ERR! command failed
      npm ERR! command sh -c npm run build
      npm ERR! > realm-integration-tests@0.1.0 build
      npm ERR! > tsc
      npm ERR!
      npm ERR! error TS2688: Cannot find type definition file for 'realm-network-transport'.
      npm ERR!   The file is in the program because:
      npm ERR!     Entry point of type library 'realm-network-transport' specified in compilerOptions
      

      We suspect possibly some kind of race condition here? Maybe install-local is proceeding before the types have been generated which results in an error.

      Workaround for now is to remove rm -rf dist from realm-network-transport's package.json, but this means we cannot guarantee we are starting from a clean state. For some reason, the same issue does not affect @realm.io/utils which also has rm -rf dist in its prepare – perhaps because it is not a direct dependency of the tests?

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: