Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.

Flow libdef only works with ESM, not CommonJS #3

Open
yeiniel opened this issue Mar 27, 2018 · 1 comment
Open

Flow libdef only works with ESM, not CommonJS #3

yeiniel opened this issue Mar 27, 2018 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@yeiniel
Copy link

yeiniel commented Mar 27, 2018

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
@novemberborn
Copy link
Member

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! 😄

@novemberborn novemberborn changed the title Flow libdef do not support using AVA as Commonjs module Flow libdef only works with ESM, not CommonJS Apr 1, 2018
@sindresorhus sindresorhus transferred this issue from avajs/ava May 2, 2019
@sindresorhus sindresorhus added the help wanted Extra attention is needed label May 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants