jest icon indicating copy to clipboard operation
jest copied to clipboard

Files are not transformed when there is nested `package.json` file

Open latata opened this issue 4 years ago • 3 comments

🐛 Bug Report

Let's say I have second package.json file in the director my-package. When I run tests using jest from the project root directory the files within my-package dir are not transformed.

Error message:

 Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • 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/en/configuration.html

To Reproduce

Steps to reproduce the behavior:

  1. create new directory within your project
  2. create new package.json files in the created dir
  3. create test file using ES6 imports
  4. run tests from the root dir
  5. error Jest encountered an unexpected token

Expected behavior

Files within directories containing another package.json file should be transformed.

envinfo

  System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
  Binaries:
    Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
  npmPackages:
    jest: ^24.8.0 => 24.8.0 

latata avatar May 07 '20 08:05 latata

I got similar error and created a new issue with reproduction detail (ex. link to repo). Please see https://github.com/facebook/jest/issues/10647

masmatsum avatar Oct 19 '20 08:10 masmatsum

@latata I found the solution for my own case. If you are using .babelrc.js, https://github.com/facebook/jest/issues/10647#issuecomment-747794046 may help you.

masmatsum avatar Dec 18 '20 00:12 masmatsum

funny ... renaming a file to fix such an issue worked surprisingly well, as mentioned in https://github.com/facebook/jest/issues/9996#issuecomment-747795051 Thanks :)

felipenmoura avatar Aug 01 '22 18:08 felipenmoura

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Aug 01 '23 19:08 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Aug 31 '23 19:08 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar Oct 01 '23 00:10 github-actions[bot]