sindresorhus / ow

Function argument validation for humans
https://sindresorhus.com/ow/
MIT License
3.8k stars 105 forks source link

bug with esm #215

Closed SimonSiefke closed 2 years ago

SimonSiefke commented 3 years ago

The export default doesn't seem to work correctly with esm and throws an error: TypeError: Cannot read property 'minLength' of undefined

Reproduction Repo: https://github.com/SimonSiefke/ow-bug

import ow from 'ow';

const unicorn = input => {
    ow(input, ow.string.minLength(5));
};

unicorn(3); // throws TypeError: Cannot read property 'minLength' of undefined





For now i am using this workaround (which is a bit ugly):

import owDefault from "ow";

// @ts-ignore
const ow = /** @type {import('ow').default} */ (owDefault.default);

const unicorn = (input) => {
  ow(input, ow.string.minLength(5));
};

unicorn(3); // works as expected
marliotto commented 3 years ago

I have the same problem with v0.27.0

HaolinHom commented 3 years ago

I have the same problem.

import ow from 'ow';

ow.array.ofType(...);

TypeError: Cannot read property 'ofType' of undefined