traverse1984 / oxide.ts

Rust's Option<T> and Result<T, E>, implemented for TypeScript.
MIT License
517 stars 19 forks source link

Webpack chokes on version 1.0.0 #3

Closed najamelan closed 2 years ago

najamelan commented 2 years ago

I'm using oxide.ts in a project that I try to test with cypress. Cypress uses webpack. When switching from oxide.ts 0.9.12 to 1.0.0, my application runs fine in the vite dev server, but when testing with cypress I get the following error when I try to import a module from my app in the cypress integration test:

Error: Webpack Compilation Error
./src/store/auth.ts
Module not found: Error: Can't resolve 'oxide.ts' in '<path>/cypress2/src/store'
resolve 'oxide.ts' in '<path>/cypress2/src/store'
  Parsed request is a module
  using description file: <path>/cypress2/package.json (relative path: ./src/store)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[<path>/cypress2/src/store/node_modules]
[<path>/cypress2/src/node_modules]
[<path>/node_modules]
[/data/node_modules]
[/node_modules]
[<path>/cypress2/node_modules/oxide.ts]
[<path>/cypress2/node_modules/oxide.ts.js]
[<path>/cypress2/node_modules/oxide.ts.json]
[<path>/cypress2/node_modules/oxide.ts.jsx]
[<path>/cypress2/node_modules/oxide.ts.mjs]
[<path>/cypress2/node_modules/oxide.ts.coffee]
[<path>/cypress2/node_modules/oxide.ts.ts]
[<path>/cypress2/node_modules/oxide.ts.tsx]
[<path>/cypress2/node_modules/oxide.ts/index]
[<path>/cypress2/node_modules/oxide.ts/index.js]
[<path>/cypress2/node_modules/oxide.ts/index.json]
[<path>/cypress2/node_modules/oxide.ts/index.jsx]
[<path>/cypress2/node_modules/oxide.ts/index.mjs]
[<path>/cypress2/node_modules/oxide.ts/index.coffee]
[<path>/cypress2/node_modules/oxide.ts/index.ts]
[<path>/cypress2/node_modules/oxide.ts/index.tsx]
 @ ./src/store/auth.ts 1:0-38 42:24-28 42:31-35
 @ ./cypress/integration/0-test-cypress/todo.spec.js
 @ multi ./cypress/integration/0-test-cypress/todo.spec.js

Seems like it can't find the entry point for the lib. So I had a quick look at the package.json and the difference seems to be the switch from "main" to "exports". And effectively when I add the "main", even leaving exports in place the issue get's resolved.

Not sure where the blame lies for this one, whether it's a problem with package.json or with webpack. If you need a MRE, let me know.

najamelan commented 2 years ago

Hmm, I'm getting lost a bit in the cypress repository, but it might be that they use webpack 4, which does not support exports.

Yes, I think that's the problem actually. Looking through my other dependencies, everything seems to have a main key in package.json, even when they also supply exports.

Maybe it's worth keeping main around for now, for compatibility.

traverse1984 commented 2 years ago

Thanks for raising this, I'll take a look soon.

traverse1984 commented 2 years ago

I have pushed/published a new release which addresses this and makes a couple of other planned changes. You should be able to install under the same tag as before.

https://www.npmjs.com/package/oxide.ts/v/1.0.0-next.10

Does this release also fix the problem you are having? I'd initially thought that main/exports were mutually exclusive but it seems that exports just overrides main - I'm not sure how this will play ball with webpack 4.

Cheers

najamelan commented 2 years ago

Yes! this solves the issue. As I said, other packages I checked just seem to have them side by side as well. Now im trying to make the webpack 4 in cypress accept nullish operator...sigh...

Thanks for the quick fix ;)

ps: actually, let's hope this saves my day: https://adamlynch.com/preprocess-cypress-tests-with-vite/