Flow libdef only works with ESM, not CommonJS
yeiniel opened this issue · comments
Description
Currently Flow libdef definition shipped with ava 1.0.0-beta.3 do not support using ava as a Commonjs module. I realize that ava recommend using babel but the project source code do not use babel. I know that when running ava babel is implicitly used but i don't think using different EcmaScript flavours is correct.
Test Source
/** Test case for the package entry point */
// @flow
"use strict";
const test = require("ava");
const mlTrainerApi = require(".");
test("expose the Application symbol", t => {
t.truthy(mlTrainerApi.Application);
});
Error Message & Stack Trace
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/index.test.js:10:1
Cannot call test because a callable signature is missing in module ava [1].
[1] 7│ const test = require("ava");
8│ const mlTrainerApi = require(".");
9│
10│ test("expose the Application symbol", t => {
11│ t.truthy(mlTrainerApi.Application);
12│ });
13│
Found 1 error
Config
None
Command-Line Arguments
Copy your npm build scripts or the ava
command used:
npx flow check
Environment
Node.js v8.10.0
linux 4.15.0-12-generic
ava version 1.0.0-beta.3
npm version 5.6.0
If I recall correctly, Flow doesn't let you define a module that can be used both as ESM and CommonJS. I did manage to get this to work in TypeScript.
Perhaps there is a way to import the TestInterface
and cast the const test
to that? I have to admit that I don't know much about Flow — writing the current definition was already quite tricky. If somebody else has a solution please let us know! 😄