reasonml-community/bs-express

es6 import issue

joprice opened this issue · 6 comments

When using bs-express with es6 modules, I get the error:

TypeError: Express is not a function

If I create the following binding locally, I don't get the error:

[@bs.module "express"] external express: unit => 'a = "default";

It seems that express is set up to be used with a few different module patterns: https://github.com/expressjs/express/blob/431f65305eb78eba337356ec7637e4ee13d84195/lib/express.js#L28

I saw a similar change here https://github.com/apollographql/reason-apollo/pull/80/files and hit something suspiciously similar here rhysforyou/bs-enzyme#14.

I'm a bit worried that changing this will break the commonjs usage. I don't know enough about the interop between all the different module specs.

What happens if you're more specific about the module system used in bs-express?

"package-specs": {
    "module": "commonjs",
    "in-source": true
  },

Actually I just switched it and I get it with commonjs or es6.

@joprice Is this still an issue?

Not sure. I ended up importing the file from js to get around it. If I get some free time soon I'll try it again.

sync commented

facing same issue with latest release and am using es6, also using latest bucklescript (v5)

sync commented

and yes this fixes it:

[@bs.module "express"] external express: unit => express = "default";

let app = express();
get(app, "*", (_, res) => send(res, "hi")) /* )*/ /*   */;

let default = app;