I wrote below code to export other module:
index.js
file:
// @flow
export UserModel from './UserModel';
UserModel.js
file:
// @flow
import Sequelize from 'sequelize';
export const PostgresDB = new Sequelize('...');
const UserModel = PostgresDB.define('user', {...});
export default UserModel;
Above code throws:
src/index.js:3
3: export UserModel from './UserModel';
^^^^^^^^^ Unexpected identifier
Of course, export { default as UserModel } from './UserModel';
is right. But I use babel-plugin-add-module-exports
to export files like commonJS.
What can I do for this?
The export Foo from "Bar";
syntax is still in proposal phase (i.e. it is not standard yet) and we just haven't gotten to implementing experimental support for it yet.
For now, if you're wanting to forward the default export from another module, your best bet is probably to do export {default} from "./UserModel";
.
I'll leave this issue open to track experimental support for the aforementioned proposal.
@jeffmo Then, I believe Flow supports export default from
if this proposal become a draft like async/await.
I believe that it is the same case for this one since ./file.js
, which imports ./index.js
, which is reexporting from ./common.js
is erroring with This module has no named export called sync
// ./common.js
export const sync = () => {};
// ./index.js
export * from './common';
// ./file.js
import {
sync,
} from './index';
Most helpful comment
The
export Foo from "Bar";
syntax is still in proposal phase (i.e. it is not standard yet) and we just haven't gotten to implementing experimental support for it yet.For now, if you're wanting to forward the default export from another module, your best bet is probably to do
export {default} from "./UserModel";
.I'll leave this issue open to track experimental support for the aforementioned proposal.