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

transformIgnorePatterns won't exclude symlinked modules #5108

Closed
jony89 opened this issue Dec 18, 2017 · 12 comments
Closed

transformIgnorePatterns won't exclude symlinked modules #5108

jony89 opened this issue Dec 18, 2017 · 12 comments

Comments

@jony89
Copy link

jony89 commented Dec 18, 2017

What is the current behavior?

While trying to ignore node_modules except modules that are symlinked, jest or babel-jest won't transpile this modules as well.

** steps to reproduce **

I've created repo to reproduce and steps are inside : https://github.com/jony89/jest-symlinked-pkgs-repro

  1. create packages : pkg1, pkg2.
  2. make pkg1 to be dependent on pkg2 using symlinking.
  3. use es6 feature in pkg2 (import...)

use the following jest.config.js in pkg1 :

  "transform": { 
    "^.+\\.js?$": "babel-jest"
  },
  "collectCoverageFrom": ["src/**/*.{js}"],
  "transformIgnorePatterns": [
    "/node_modules/(?!@pkg2)"
  ],
  "setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
  "unmockedModulePathPatterns": [
    "<rootDir>/node_modules/react",
    "<rootDir>/node_modules/react-dom"
  ],
  "moduleNameMapper": {
    "\\.(gif)$": "<rootDir>/__mocks__/imgMock.js"
  }
}

and add the .babelrc file

{
  "presets": [
    ["env", { "modules": false }],
    "react",
    "flow"
  ],
  "plugins": [
    "transform-class-properties",
    "transform-object-rest-spread",
    "flow-react-proptypes"
  ],
  "env": {
    "test": {
      "presets": [
        ["env"],
        "react",
        "flow"
      ],
      "plugins": [
        "transform-class-properties",
        "transform-object-rest-spread",
        "flow-react-proptypes",
        "transform-es2015-modules-commonjs"
      ]
    }
  }
}

** steps to reproduce **

just try to run jest for any simple test that uses these to pkgs

What is the expected behavior?

pkg2 should be transpiled

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

npm : 5.5.1
node : 8.4.1
jest : 21.3.0-beta.10

@SimenB
Copy link
Member

SimenB commented Dec 18, 2017

Can you try this with the stable jest 22? There have been symlink fixes there.

If it still fails, can you create a repository with your repro? It's a bit easier to work with. Thanks!

@jony89
Copy link
Author

jony89 commented Dec 18, 2017

Hey,

jest 22 does not solve this issue.

I've created repo to reproduce and steps are inside : https://github.com/jony89/jest-symlinked-pkgs-repro

@unindented
Copy link

@SimenB can you give some pointers on what areas of the codebase I should look at if I wanted to fix this? I've used Jest, but I've never dug into its internals.

@jony89
Copy link
Author

jony89 commented Jan 2, 2018

I can start dig into this also with some guidance ?

@SimenB
Copy link
Member

SimenB commented Jan 5, 2018

@jony89
Copy link
Author

jony89 commented Jan 8, 2018

I've debugged it and the code was correct.

It seems that pkg2 must hold .babelrc as well in order to be transformed with babel.

after adding .babelrc to pkg2 it works well, seems like the correct behavior(?)

@petermikitsh
Copy link

I'm still experiencing this issue. pkg1 and pkg2 both have a .babelrc at the root.

I also have this in my jest pkg1 jest config:

"transformIgnorePatterns": [
    "/node_modules/(?!@pkg2)"
  ],

pkg2 will not compile, though.

    /Users/git/.../packages/pkg2/dist/keygen.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export var foo = 'bar';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export

@petermikitsh
Copy link

Found my solution in #6229. I'm using Babel 7 and that has an impact on things.

@benmccormick
Copy link
Contributor

I just ran into this issue with symlinks, and found that the issue was my babel config from my current directory didn't apply to the symlinked directory (because the file is passed to babel with its "real" path not its symlinked path)

Placing a copy of my .babelrc (Babel 6) beneath node_modules in the directory it was being symlinked from resolved the issue.

So I think the fix here is to pass the local path to babel and not expand the symlink.

@gmichaeljaison
Copy link

gmichaeljaison commented Oct 1, 2020

@benmccormick It's been long time since your previous answer. Did you upgrade to use Babel 7 now? If yes, how did you tackle the symlink problem? Thanks.

@benmccormick
Copy link
Contributor

@gmichaeljaison I've switched jobs since then and don't really remember how this played out, sorry.

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants