akita icon indicating copy to clipboard operation
akita copied to clipboard

Akita 7 fails in jest because we are missing type:module from package.json

Open leon opened this issue 2 years ago • 12 comments

Is this a regression?

Yes

Description

The akita package.json does not include "type": "module" https://unpkg.com/browse/@datorama/[email protected]/package.json

and node will treat "main" field as commonjs if not specified. https://nodejs.org/api/esm.html#esm_enabling

I'm not sure if this is the only thing that needs doing for it to work, but I'm guessing someone else knows :)

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

SyntaxError: Unexpected token 'export'

Please provide the environment you discovered this bug in

jest 27.4.3
akita 7.0.1

Anything else?

No response

Do you want to create a pull request?

No

leon avatar Dec 02 '21 10:12 leon

+1 Same here with

jest 27.4.3 akita 7.0.1

MaChristmann avatar Dec 09 '21 09:12 MaChristmann

any workarounds? Adding "type": "module" to node_modules/@datorama/akita/package.json doesn't help.

Burgov avatar Dec 30 '21 13:12 Burgov

I am also getting this.

Diff: https://github.com/tony/cv/commit/bf4d4a1b0a1a31dad15354dba41d3cffdc2ae1ba CI run w/ error: https://github.com/tony/cv/runs/4826668166?check_suite_focus=true

tony avatar Jan 15 '22 20:01 tony

@NetanelBasal Any details on this?

tony avatar Jan 15 '22 20:01 tony

https://stackoverflow.com/questions/49263429/jest-gives-an-error-syntaxerror-unexpected-token-export

NetanelBasal avatar Jan 15 '22 20:01 NetanelBasal

@NathanAlcantara I appreciate the link! Thank you.

Hm, I still don't have an idea what's going on.

Any idea on what's changed in Akita between 6 and 7 that could be causing this issue?

Regarding the the type: module in package.json, what would be the impact on that? (I assume there are structural / build reasons not to do that?)

tony avatar Jan 15 '22 20:01 tony

I'm not sure. I didn't change anything. I think it is something with Jest.

NetanelBasal avatar Jan 15 '22 21:01 NetanelBasal

@NetanelBasal if I downgrade Akita to vrs 6.2.0, it works fine with same version of jest.

DonTomato avatar Jan 16 '22 07:01 DonTomato

@NetanelBasal And at https://github.com/datorama/akita/issues/778#issuecomment-1013750863 I have a diff and CI runs shows specifically that updating 6 -> 7

However, that still doesn't preclude the issue being rooted our own project's environmental / config issues rather than akita's build/packaging/etc. It could still be our environment's were / have become incorrect and something underneath the hood, e.g. an inner dependency, brought it to the forefront

tony avatar Jan 16 '22 14:01 tony

We are not doing anything special. We're using Nx to build the package. Is there any issue in Nx regarding what you describe?

NetanelBasal avatar Jan 17 '22 06:01 NetanelBasal

Maybe this will help you https://github.com/datorama/akita/issues/781#issuecomment-1018856090

theorlovsky avatar Jan 21 '22 21:01 theorlovsky

@NetanelBasal I consulted the NX docs and could not find any mentions on how to build multiple module types. Pre nx13 akita had many module systems bundled and referenced in the package.json, now only the ESModule version is bundled. My personal preference would be to try to continue to support multiple module types. Maybe building with @nrwl/angular:package would support more module types out of the box?

kvetis avatar Aug 02 '22 12:08 kvetis