cube-js / cube

📊 Cube — Universal semantic layer platform for AI, BI, spreadsheets, and embedded analytics
https://cube.dev
Other
17.96k stars 1.78k forks source link

Export in JS utilities function #8885

Open arkadiusz-swierczek-pm opened 3 weeks ago

arkadiusz-swierczek-pm commented 3 weeks ago

Describe the bug Using default export throws error on runtime: TypeError: Cannot read properties of null (reading 'declarations')

To Reproduce Steps to reproduce the behavior:

  1. Create directory structure described in https://cube.dev/docs/product/data-modeling/dynamic/code-reusability-export-and-import#import-from-parent-directories
  2. Replace content of model/shared_utils/utils.js with
    const _capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
    export { _capitalize as capitalize }

Expected behavior I am expecting to be able to use the default export without runtime error.

Version: 0.36.0

Additional context I believe, that root case is located in packages/cubejs-schema-compiler/src/compiler/transpilers/ImportExportTranspiler.ts

igorlukanin commented 2 weeks ago

I am expecting to be able to use the default export without runtime error.

Hey @arkadiusz-swierczek-pm 👋 Could you please elaborate on this? Is there anything that you can not accomplish without default exports?

arkadiusz-swierczek-pm commented 2 weeks ago

Hey

I made an error in the title and the description. The problem doesn't occured when using default export, but named export.

I have created minimal example showing how to get the error: https://github.com/arkadiusz-swierczek-pm/cube-8885, and also PR: https://github.com/cube-js/cube/pull/8774

Please also take a look at the link:, that show another way to get the error https://astexplorer.net/#/gist/c9de828dbc29e8df9bf88e8a58c58842/4ef985fb1fcfb3c9a0c22c1561f08e11de8d6714