YuriGor / deepdash

eachDeep, filterDeep, findDeep, someDeep, omitDeep, pickDeep, keysDeep etc.. Tree traversal library written in Underscore/Lodash fashion
https://deepdash.io/
MIT License
272 stars 12 forks source link

webpack issue with "type": "module" in package.json #78

Closed jcamden closed 3 years ago

jcamden commented 3 years ago

Greetings, YuriGor!

I'm enrolled in your Super Star Support Plan. I wanted to give you a heads up about an apparently webpack-related issue: I'm using deepdash-es for a bad idea that I had about running all of my cypress tests recursively from a single object. I'm running cypress with a questionable alpha plugin, cypress-webpack-preprocessor-v5 (because webpack 5 supports yarn 2 pnp) and using ts-loader. So in that kind of crazy context, when I attempt to use deepdash-es, I get an incredibly cryptic error from the cypress test runner:

Error: Webpack CompLooked for and couldn't find the file at the following paths:resolve 
only because it was resolved as fully specified (probably because the origin is a '*.mjs' file 
or a '*.js' file where the package.json contains '"type": "module"'). The extension in the 
request is mandatory for it to be fully specified. Add the extension to the request.

What? Well... after fiddling around with whatever was seemingly referenced by the error, I found that unplugging deepdash-es and removing "type" : "module" from package.json resolves the issue. I don't quite understand, to be honest, but maybe you will. Thanks very much for the great package!

YuriGor commented 3 years ago

Hi! Looks like this issue is related to #74 and #77, looks like I broke package.json by this #74 change. I will check all this stuff as soon as i will have free minute :(

jcamden commented 3 years ago

Hi @YuriGor, just wanted to bump this. The workaround mentioned above (unplugging deepdash and removing "type" : "module" from package.json) still works, so not a big problem; but it seemed good to give updated confirmation of the issue. Thanks again for deepdash!

YuriGor commented 3 years ago

Hi, thank you for patience, I had no time. Will try to look on this week.

YuriGor commented 3 years ago

Hi @jcamden thank you for motivation, otherwise I would probably never made myself to care about this :) Could you please check v5.3.7? both packages 'deepdash' and 'deepdash-es' was updated to support recent nodejs "exports" package feature, so if you have nodejs>12 - it should help. Webpack should also support this feature, so please try.

jcamden commented 3 years ago

Hi @YuriGori, the vs-code Typescript server compiles imports from 5.3.7 without any need to unplug and modify the package.json. Screenshot from 2021-04-18 19-57-33 However, Webpack throws an error. Here it is for your standalone method (which is cool):

ERROR in ...superTopSecretUI/SpaceAlienPhone.tsx 23:19-52
Module not found: Error: Package path ./standalone is not exported from package /secureComputer/topSecretProjects/secret-intergalactic-social-media-platform/.yarn/cache/deepdash-es-npm-5.3.7-d50725dacf-97ced85397.zip/node_modules/deepdash-es/ (see exports field in /secureComputer/topSecretProjects/secret-intergalactic-social-media-platform/.yarn/cache/deepdash-es-npm-5.3.7-d50725dacf-97ced85397.zip/node_modules/deepdash-es/package.json)

Same for cherry-pick:

ERROR in ...superTopSecretUI/SpaceAlienPhone.tsx 23:19-52
Module not found: Error: Package path ./mapValuesDeep is not exported from package /secureComputer/topSecretProjects/secret-intergalactic-social-media-platform/.yarn/cache/deepdash-es-npm-5.3.7-d50725dacf-97ced85397.zip/node_modules/deepdash-es/ (see exports field in /secureComputer/topSecretProjects/secret-intergalactic-social-media-platform/.yarn/cache/deepdash-es-npm-5.3.7-d50725dacf-97ced85397.zip/node_modules/deepdash-es/package.json)

Have a baby now, but when I get time, I will check this out further. Thanks again!

YuriGor commented 3 years ago

Thanks for testing, will dig deeper then!

YuriGor commented 3 years ago

Hi @jcamden here is a demo repo deepdash+webpack https://github.com/YuriGor/deepdash-webpack works fine for me could you please repro your issue using this as starting point?

YuriGor commented 3 years ago

also please try just 'deepdash', not 'deepdash-es' - 'deepdash' is now both compatible with esm and cjs

P.S. looks like in typescript, package exports property are still in progress: https://github.com/microsoft/TypeScript/issues/33079 but it still should work fine old way.

jcamden commented 3 years ago

Ah, you are right, @YuriGor: the issue was that Typescript doesn't support package exports (until 4.3 in May, evidently); but the lodash mixin method works just fine without unplugging since 5.3.7. Thanks again for the very superstar support and for the excellent package. Much better than my own attempts at deep-x-lodash-method functions 👍