Skip to content
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 file #74

Open
nickmcsimpson opened this issue Dec 12, 2024 · 2 comments
Open

Jest failed to parse file #74

nickmcsimpson opened this issue Dec 12, 2024 · 2 comments

Comments

@nickmcsimpson
Copy link

Not sure if this is an issue with my implementation or a problem with the "default as" export syntax not being supported by Jest.

Error message:

  ● 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

Error location

    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export {default as create} from "./create.js";
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

      1 | import React, { useMemo, useRef } from 'react';
    > 2 | import Tree, { CustomNodeElementProps, RawNodeDatum } from 'react-d3-tree';

Thoughts on how this can be resolved?

@nickmcsimpson
Copy link
Author

The workaround is to force babel to transform all of the dependent d3 packages. I added based on this similar issue

// jest.config.js
module.exports = {
...
    transformIgnorePatterns: ['/node_modules/(?!(d3-\\w+)/)'],
};

This allows the tests to run, but I'm not sure how much overhead this adds to tests that are already quite slow. Attempting to mock the react-d3-tree components/interfaces entirely hadn't gotten me anywhere yet.

@vinzdeveloper
Copy link
Owner

i think its time to upgrade jest and babel transform plugins to support latest ES scripts. let me see if it helps!

Thanks for raising!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants