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

next-intl/link is causing an error in tests #452

Closed
dgknca opened this issue Aug 14, 2023 · 5 comments
Closed

next-intl/link is causing an error in tests #452

dgknca opened this issue Aug 14, 2023 · 5 comments
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@dgknca
Copy link

dgknca commented Aug 14, 2023

Description

The version I'm using: 3.0.0-beta.9

There is no problem while development but I can't fix this error in tests. I've attached a repository you can peek at that reproduces the error in the simplest way. This error occurs in all components where we've used the I18nLink component. This causes all of our component tests to fail.

 FAIL  src/components/Card/Card.spec.tsx
  ● 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.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /Users/dgknca/Desktop/next-intl-reproduce/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next-intl/dist/src/link/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default } from './Link';
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

      10 |   return <Link href={href} locale="en" />;
      11 | }
    > 12 |
         | ^

      at Runtime.createScriptFromCode (node_modules/.pnpm/[email protected]/node_modules/jest-runtime/build/index.js:1496:14)
      at Object.<anonymous> (src/components/I18nLink.tsx:12:54)
      at Object.<anonymous> (src/components/Card/Card.tsx:12:58)
      at Object.<anonymous> (src/components/Card/Card.spec.tsx:7:54)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.758 s
Ran all test suites.
 ELIFECYCLE  Test failed. See above for more details.

Mandatory reproduction URL (CodeSandbox or GitHub repository)

https://github.com/dgknca/next-intl-jest-error-reproduce

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. Run tests with pnpm test command
  3. See the error SyntaxError: Unexpected token 'export'

Expected behaviour

No error

@dgknca dgknca added bug Something isn't working unconfirmed Needs triage. labels Aug 14, 2023
@amannn
Copy link
Owner

amannn commented Aug 14, 2023

Thanks for the great bug report @dgknca!

I've just published [email protected] which seems to solve the issue in your reproduction (however you need to add NextIntlClientProvider for the test to pass, but that's unrelated).

Can you try it out in your app and let me know if it works? Thank you!

@dgknca
Copy link
Author

dgknca commented Aug 14, 2023

yes, it works. thanks!

@dgknca dgknca closed this as completed Aug 14, 2023
@cjambrosi
Copy link

Hello @amannn. I have the same error in version [email protected] with [email protected]. I tried to solve it with the solution above, but I was not successful.

@amannn
Copy link
Owner

amannn commented Aug 29, 2023

@cjambrosi Can you create a minimal reproduction and open a new issue that references it?

@cjambrosi
Copy link

cjambrosi commented Aug 30, 2023

@amannn, thanks for replying. I opened a new issue and created a repository to reproduce the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

3 participants