Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Package does not get transpiled in Jest, like react-markdown #55031

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

Open
1 task done
weyert opened this issue Sep 6, 2023 · 3 comments
Open
1 task done

Package does not get transpiled in Jest, like react-markdown #55031

weyert opened this issue Sep 6, 2023 · 3 comments
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity. Testing Related to testing with Next.js.

Comments

@weyert
Copy link

weyert commented Sep 6, 2023

Link to the code that reproduces this issue or a replay of the bug

https://github.com/weyert/nextjs-jest-markdown

To Reproduce

  1. Start the application with npm run dev
  2. Navigate to http://127.0.0.1:3000
  3. Note that This is a Markdown paragraph get rendered
  4. Run npm run test
  5. Notice that jest fail forsrc/__tests__/pages/StartPage.test.tsx and src/components/__tests__/PageContent.test.tsx

Current vs. Expected behavior

I would expect that I can write unit tests with packages that get transpiled instead I am getting the error:

  ● 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/weyert/Development/Projects/Reproductions/markdown-jest-next/node_modules/vfile/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export {VFile} from './lib/index.js'
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.14.0
      npm: 8.19.3
      Yarn: 1.22.19
      pnpm: 8.7.3
    Relevant Packages:
      next: 13.4.20-canary.18
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5
    Next.js Config:
      output: N/A

Which area(s) are affected? (Select all that apply)

Jest (next/jest)

Additional context

I made a reproduction repository (see above) for an problem I am experiencing in a work project that uses an older version of Next.js (13.4.12) but planning to upgrade to 13.4.20 once its released to solve my modularize import issue from a previous ticket.

I am trying to write unit tests for components that consume the react-markdown package but fail to do so

@weyert weyert added the bug Issue was opened via the bug report template. label Sep 6, 2023
@github-actions github-actions bot added the Testing Related to testing with Next.js. label Sep 6, 2023
@weyert
Copy link
Author

weyert commented Sep 6, 2023

If I add vfile to the transpilePackages-configuration in next.config.js I am getting the following error:

Cannot find module '../../src/lib/index.js' from 'node_modules/vfile/index.js'

The code in the vfile/index.js file is:

export {VFile} from './lib/index.js'
``

I am not sure why the path changes to `'../../src/lib/index.js'`?

@weyert
Copy link
Author

weyert commented Sep 6, 2023

@shuding Ticket :)

@nextjs-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@nextjs-bot nextjs-bot added the stale The issue has not seen recent activity. label May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity. Testing Related to testing with Next.js.
Projects
None yet
Development

No branches or pull requests

2 participants