javandres opened a new issue, #540:
URL: https://github.com/apache/arrow-js/issues/540

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   A webpack 5 bundle that imports only `StructRow` crashes when it loads:
   
   ```js
   import { StructRow } from 'apache-arrow';
   console.log(StructRow);
   ```
   
   ```
   ReferenceError: Cannot access 'get_instance' before initialization
   ```
   
   This happens with apache-arrow 17.0.0 and 21.2.0 on webpack 5.112, in both 
production and development mode. esbuild and rollup bundles of the same file 
run fine.
   
   **Cause.** `row/struct` imports `visitor/get` before anything else. 
`visitor/get` imports `vector`, and the static initializer of `Vector` calls 
`getVisitor.getVisitFnByTypeId()` for every type id at load time, while 
`visitor/get` has not finished evaluating. Through the package index, `vector` 
is evaluated first and the cycle settles. The package declares `"sideEffects": 
false`, though, so webpack sends a named import straight to `row/struct.mjs` 
and skips the index. Node shows the same thing without a bundler when 
`row/struct.mjs` is imported directly:
   
   ```
   ReferenceError: Cannot access 'getVisitor' before initialization
       at file:///.../node_modules/apache-arrow/vector.mjs:292:21
   ```
   
   I bundled each of the 165 exports of 21.2.0 on its own with webpack. 
`StructRow` is the only one that crashes. `MapRow` does not, because `row/map` 
imports `Vector` before the visitors.
   
   The bundle test in `test/bundle` does not catch it. `webpack-stream` merges 
`test/bundle/*.js` into one `main-bundle.js`, and in that bundle the earlier 
files load `vector` first.
   
   **Where it shows up.** kepler.gl 3.3.0-alpha.22 imports `StructRow` from 
`@kepler.gl/utils`, and apps that build kepler.gl with webpack now fail on load.
   
   **Workaround.** A webpack rule that keeps the index in the path: `{test: 
/[\\/]node_modules[\\/]apache-arrow[\\/]/, sideEffects: true}`.
   
   Related: #63 (circular dependencies), #73 (`sideEffects: false`).
   
   ### Component(s)
   
   JavaScript
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to