Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-12636

[JS] ESM Tree-Shaking produces broken code

    XMLWordPrintableJSON

Details

    Description

      When a JS application depends on `apache-arrow` or any of the ESM variants, Arrow's package.json declares `sideEffects: false` which allows bundlers like Webpack or Rollup to remove all code that's evaluated at the top level of all modules (any code that isn't explicitly imported can be pruned).

       

      However, there are important top-level side effects that Arrow relies on, e.g. for binding methods on types:

      https://github.com/apache/arrow/blob/c0445d69088a6fbd9c026ecac6a99c6cd4df4865/js/src/vector/index.ts#L167-L179

       

      So currently, any JS app that uses tree-shaking and depends on `apache-arrow` or the ESM variants will throw if any of those methods are called, e.g. in my case I see `TypeError: e._chunks[t].get is not a function` when calling `table.get`.

       

      Indeed switching to the CJS variants like `@apache-arrow/es2015-cjs` fixes the issue, since the Arrow build does not inject `sideEffects: false` into its package.json for non-ESM variants.

       

      For reference, the `sideEffects: false` logic was introduced in this PR and issue:

      https://github.com/apache/arrow/pull/8418/

      https://issues.apache.org/jira/browse/ARROW-10255

       

      Attachments

        Issue Links

          Activity

            People

              paul.e.taylor Paul Taylor
              hzuo Howard Zuo
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m