2

EDIT Maybe I found the problem, would like if someone could confirm the situation: It seems like test.js is importing index.js which is importing test.js, and export has not an stop infinite-loop inclusion... Is it right? Is there any workaround like Don't include this file if it's the calling one?


I'm facing a strange problem. I'm trying to import some objects from a re-export (tcomb-react-native is not relevant here as the problem is with import/export).

|-- index.js
|-- simpleTypes.js
|-- userType.js

index.js:

export { UserType, UserTypeBase } from './test';
export { TextMax9Type } from './simpleTypes';

simpleTypes.js:

import t from 'tcomb-form-native';
export const TextMax9Type = t.refinement(t.String, s => s.length <= 9);

test.js:

import t from 'tcomb-form-native';
// import { TextMax9Type } from './'; // <----- NOT WORKING!
import { TextMax9Type } from './simpleTypes'; // <----- OK no error

export const UserTypeBase = {
    Name: TextMax9Type,
    Surname: TextMax9Type,
};

export const UserType = t.struct(UserTypeBase);

NOT WORKING error: Invalid argument props {} supplied to struct(props, [name]) combinator (expected a dictionary String-> Type)

So which is the problem with re-export that is exporting an empty object?

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
David
  • 2,741
  • 16
  • 26
  • Which is the typo? (I'm sorry I can't see it...) uh! sorry, I changed the name of the file to post the question – David Apr 26 '16 at 21:43
  • nevermind, i was totally wrong. – QoP Apr 26 '16 at 21:44
  • No, I want to re-export: http://jamesknelson.com/re-exporting-es6-modules/ and http://www.2ality.com/2015/07/es6-module-exports.html (also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) there it says I can export whatever to make it available for others... Isn't that right? – David Apr 26 '16 at 21:45
  • yeah, the file names were messing with me :P – QoP Apr 26 '16 at 21:46
  • So if you log the values, what do you see when it works vs when it doesn't? This is hard to answer without some amount of debugging. – loganfsmyth Apr 26 '16 at 22:05
  • 2
    When I simulate your situation, it seems to work for me. My .babelrc looks like this `{ "presets": ["es2015", "stage-2"], "plugins": ["transform-runtime"], "comments": false }` I think it might be something with your Babel setup. – Swimburger Apr 26 '16 at 22:11
  • Yes, I've tried this simple case and it's working also, with more complex case it's not, so I'll keep debugging to find the problem (I made an abstraction of what seemed the problem but in fact it's not... :( ) – David Apr 26 '16 at 22:14
  • 2
    If index.js imported test.js (or something that imported test.js) before simpleTypes.js, I would expect to see the error you describe. When you import a file, it means that file has to execute before the current file. If index.js imports test.js first, and then test.js imports index.js then simpleTypes.js, then test.js and simpleTypes.js will be queued to run in that order. simpleTypes.js hasn't executed yet, so index.js doesn't know what value to export, so test.js runs before `TextMax9Type` is set. Take a look at babel's transpiled code output and trying testing with lots of logging to see. – Macil Apr 26 '16 at 23:04
  • So that means that if `simpleTypes.js` is to be used by `test.js`, and `test.js`needs `index.js`, the order in `index.js` should be first `simpleTypes.js`. It's a matter of order then, right? (not infinite-loop inclusion) – David Apr 26 '16 at 23:08
  • 1
    @David exactly - just a matter of order. Note that any language with an eager module system has this same problem (Python, Scala, etc.). When lazy export getters (`export get`) are implemented, you can export `{TextMax9Type}` as a getter and this will no longer be an issue. – bcherny Apr 27 '16 at 01:13

0 Answers0