You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Dominik Moritz (Jira)" <ji...@apache.org> on 2021/07/28 23:05:00 UTC

[jira] [Commented] (ARROW-12636) [JS] ESM Tree-Shaking produces broken code

    [ https://issues.apache.org/jira/browse/ARROW-12636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17389114#comment-17389114 ] 

Dominik Moritz commented on ARROW-12636:
----------------------------------------

I can repro this issue with a small example:

{code:js}
import {Table, FloatVector} from 'apache-arrow'

// Toggle this code. When it's there, the code below works. Why???
// Table.new([FloatVector.from(new Float32Array([]))], ['a'])

const bytes2 = Uint8Array.from([65,82,82,79,87,49,0,0,255,255,255,255,120,0,0,0,16,0,0,0,0,0,10,0,12,0,6,0,5,0,8,0,10,0,0,0,0,1,4,0,12,0,0,0,8,0,8,0,0,0,4,0,8,0,0,0,4,0,0,0,1,0,0,0,20,0,0,0,16,0,20,0,8,0,0,0,7,0,12,0,0,0,16,0,16,0,0,0,0,0,0,2,16,0,0,0,28,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0,49,0,0,0,8,0,12,0,8,0,7,0,8,0,0,0,0,0,0,1,32,0,0,0,255,255,255,255,136,0,0,0,20,0,0,0,0,0,0,0,12,0,22,0,6,0,5,0,8,0,12,0,12,0,0,0,0,3,4,0,24,0,0,0,8,0,0,0,0,0,0,0,0,0,10,0,24,0,12,0,4,0,8,0,10,0,0,0,60,0,0,0,16,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,16,0,0,0,12,0,20,0,6,0,8,0,12,0,16,0,12,0,0,0,0,0,4,0,60,0,0,0,40,0,0,0,4,0,0,0,1,0,0,0,136,0,0,0,0,0,0,0,144,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,8,0,0,0,4,0,8,0,0,0,4,0,0,0,1,0,0,0,20,0,0,0,16,0,20,0,8,0,0,0,7,0,12,0,0,0,16,0,16,0,0,0,0,0,0,2,16,0,0,0,28,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0,49,0,0,0,8,0,12,0,8,0,7,0,8,0,0,0,0,0,0,1,32,0,0,0,168,0,0,0,65,82,82,79,87,49]);

const table2 = Table.from(bytes2);

console.log("table2", table2);
// thows error: Uncaught TypeError: chunks[0].toArray is not a function
console.log("table2", table2.toArray());
{code}

> [JS] ESM Tree-Shaking produces broken code
> ------------------------------------------
>
>                 Key: ARROW-12636
>                 URL: https://issues.apache.org/jira/browse/ARROW-12636
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: JavaScript
>    Affects Versions: 4.0.0
>            Reporter: Howard Zuo
>            Assignee: Paul Taylor
>            Priority: Critical
>
> 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
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)