typed-unmaintained icon indicating copy to clipboard operation
typed-unmaintained copied to clipboard

Import errors in node

Open TylorS opened this issue 6 years ago • 7 comments

TypeError: prelude_1.prop is not a function

TylorS avatar Oct 26 '17 15:10 TylorS

selection_002

Frikki avatar Oct 26 '17 19:10 Frikki

I tried using Maybe's for the first time in my life, and wanted to do a simple console.log. I got a similar result with ap via @typed/prelude: https://github.com/marcusnielsen/mostjs-labs/blob/master/src/index.ts#L11

 const log = (maybe) => prelude_1.ap(prelude_1.toMaybe(console.log), maybe);
TypeError: prelude_1.ap is not a function

I was guessing it's my fault since I've never used ap, Maybe, or this framework before. But seeming this issue, maybe it's the same bug? Any advice for moving forward?

marcusradell avatar Oct 26 '17 19:10 marcusradell

Hey @marcusnielsen there seems to be some sort of issue with the way TypeScript compiles ES2015 modules to commonjs. If you're interested in Maybe in particular, I'd suggest using @typed/maybe directly until we can figure out this issue here.

EDIT: Heres a webpackbin doing what is in your error message. https://www.webpackbin.com/bins/-KxPOhHcGP9jecQJZ6Ot

TylorS avatar Oct 26 '17 20:10 TylorS

Additionally if you're using something like webpack to bundle your application, you can add module or jsnext:main to resolve.mainFields to use the ES2015 build instead and avoid this bug.

TylorS avatar Oct 26 '17 20:10 TylorS

Using @typed/maybe worked out well! (I'm using tsc without webpack.)

Thanks for the help, I just did my first Maybe and ap , and it feels awesome 🎉

marcusradell avatar Oct 27 '17 04:10 marcusradell

I'm thinking that going forward we could just have yarn add @typed/prelude be a convenient shortcut for yarn add @typed/either @typed/functions @typed/lenses @typed/list @typed/logic @typed/math @typed/maybe @typed/objects @typed/strings but not re-export these packages from itself, but instead requiring explicit imports from the other @typed/* packages.

What do you think?

TylorS avatar Dec 31 '17 22:12 TylorS

I am much in favor of explicit imports. A convenient shortcut using @typed/prelude is preferable to re-exports.

Frikki avatar Jan 09 '18 19:01 Frikki