Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest failed to parse a file #3764

Closed
1 of 2 tasks
cam-m opened this issue Feb 1, 2023 · 11 comments
Closed
1 of 2 tasks

Jest failed to parse a file #3764

cam-m opened this issue Feb 1, 2023 · 11 comments

Comments

@cam-m
Copy link
Contributor

cam-m commented Feb 1, 2023

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

  • Yes
  • No
@timdeschryver
Copy link
Member

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

@cam-m
Copy link
Contributor Author

cam-m commented Feb 1, 2023

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
Copy link
Member

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
Copy link
Contributor Author

cam-m commented Feb 1, 2023

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
Copy link
Member

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

Did you try:

rm -rf node_modules/
yarn
yarn test

@markostanimirovic
Copy link
Member

Also, try switching to Node 14.20.0.

@cam-m
Copy link
Contributor Author

cam-m commented Feb 1, 2023 via email

@cam-m
Copy link
Contributor Author

cam-m commented Feb 1, 2023 via email

@markostanimirovic
Copy link
Member

Hi @cam-m,

Did you fix tests by switching to Node 14.20?

@cam-m
Copy link
Contributor Author

cam-m commented Feb 4, 2023 via email

@markostanimirovic
Copy link
Member

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

@ngrx ngrx locked and limited conversation to collaborators Feb 8, 2023
@markostanimirovic markostanimirovic converted this issue into discussion #3772 Feb 8, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants