Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I have two problem which can be solved with this change 1. Rollup handles only es modules. To handle commonjs there is a plugin which converts it into esm. Though it always skips module if import/export statements are found. As a result I get runtime error: "require is not defined". To workaround this I wrote custom plugin. Though it would be cool to have proper solution out of the box. ```js { name: 'relay-generated', transform(code) { // convert __generated__ requires into imports // remove after relay-compiler will be able to emit esm if (code.includes('__generated__')) { let i = -1; const paths = []; const processed = code.replace( /require\((.+__generated__.+)\)/g, (req, pathString) => { i += 1; paths.push(pathString); return `__generated__${i}`; }, ); const imports = paths.map( (p, i) => `import __generated__${i} from ${p};\n`, ); return { code: imports.join('') + processed, }; } }, }, ``` 2. Another problem is flow bug (facebook/flow#7444) which treats all not existent types as any. This leads to many type unsafe places. ```js import type {NotExistentType} from './__generated__/MyQuery.graphql'; type Props = {| my: NotExistentType |} ```
- Loading branch information