ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
8.04k stars 1.98k forks source link

Jest failed to parse a file #3764

Closed cam-m closed 1 year ago

cam-m commented 1 year ago

Which @ngrx/* package(s) are the source of the bug?

component-store, component, data, effects, entity, eslint-plugin, router-store, schematics, store-devtools, store

Minimal reproduction of the bug/regression with instructions

I'm sure I'm missing something stupid, but trying commit a PR and getting this when I run yarn test:

Test suite failed to run

Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

and the error:

SyntaxError: Cannot use import statement outside a module

    > 1 | import { EntityAdapter, createEntityAdapter } from '@ngrx/entity';
        | ^
      2 | import { Comparer, IdSelector } from '@ngrx/entity';
      3 |
      4 | import { EntityDispatcherDefaultOptions } from '../dispatchers/entity-dispatcher-default-options';

      at Runtime.createScriptFromCode (../../node_modules/jest-runtime/build/index.js:1796:14)
      at Object.<anonymous> (src/entity-metadata/entity-definition.ts:1:1)

This is just one example, I get the same issue thrown on multiple other spec files

It seemed to work fine 2 months ago?

Minimal reproduction of the bug/regression with instructions

run yarn test

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

NGRX 15.2.1 Windows 10

Other information

No response

I would be willing to submit a PR to fix this issue

timdeschryver commented 1 year ago

Hi, did you already try to clean your node_modules? Maybe a build first can also do the trick.

cam-m commented 1 year ago

Thanks @timdeschryver, yes I did try deleting node_modules a few times, and just tried your suggestion of building first. still getting the same errors. I did commit and push changes and the ci builds and tests appear to be working so it must be something Im missing in my setup. I'm a bit stumped.

markostanimirovic commented 1 year ago

Minimal reproduction of the bug/regression with instructions

run yarn test

Hi @cam-m 👋

You probably saw in the issue template description that reproduction is required when reporting a bug. Please provide Stackblitz or GitHub repo with a reproduction.

cam-m commented 1 year ago

Thanks @markostanimirovic , I'm not sure how i would provide a reproduction since all i've got is a fork of the ngrx/platform repo with some changes for a pull request. When I push the changes to the PR the CI run tests appear to work and pass fine. They just don't work on my machine.

I will try checking out the repo fresh and see if that fixes it.

markostanimirovic commented 1 year ago

Oh, I thought you have this issue in another repo. 😅

Did you try:

rm -rf node_modules/
yarn
yarn test
markostanimirovic commented 1 year ago

Also, try switching to Node 14.20.0.

cam-m commented 1 year ago

Ha no worries :)

I did try that with no success (although not entirely at the cmd line).

I’ll post back on the result of a clean repo build.

cam-m commented 1 year ago

ooh you might be onto something there, I did recently bump up node so will look at that too

markostanimirovic commented 1 year ago

Hi @cam-m,

Did you fix tests by switching to Node 14.20?

cam-m commented 1 year ago

No that didn’t work unfortunately.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Marko Stanimirović @.> Sent: Sunday, February 5, 2023 6:44:53 AM To: ngrx/platform @.> Cc: Cameron Maunder @.>; Mention @.> Subject: Re: [ngrx/platform] Jest failed to parse a file (Issue #3764)

Hi @cam-mhttps://github.com/cam-m,

Did you fix tests by switching to Node 14.20?

— Reply to this email directly, view it on GitHubhttps://github.com/ngrx/platform/issues/3764#issuecomment-1416834939, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAEZXDNHYP5WVC23ELXKI63WV2WTLANCNFSM6AAAAAAUNEFDSY. You are receiving this because you were mentioned.Message ID: @.***>

markostanimirovic commented 1 year ago

I'll convert this issue to a Q&A discussion. I use these versions on my machine (Windows 11 OS):

Node: v16.16.0
Yarn: v1.22.19