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

Cannot find package root when ts-jest is symlinked instead of being installed #823

Closed
KSXGitHub opened this issue Oct 21, 2018 · 14 comments
Closed
Labels
Confirmed Bug is confirmed

Comments

@KSXGitHub
Copy link

This line of code is supposed to find package root, it works when I install ts-jest using yarn or npm but doesn't when I use pnpm.

Unlike npm and yarn, pnpm wants to save disk space by symlinking packages from node_modules/.registry.npmjs.org to node_modules. This makes package root not ../../ relative to ts-jest but ../../../../ relative to ts-jest causing it to print warnings.

Suggestion

Instead of just assuming package root to be in ../../, search for package root in every ancestor directory starting with ../.

... BTW, I have a package that lists all ancestor directories.
@huafu huafu added the Confirmed Bug is confirmed label Oct 21, 2018
@huafu
Copy link
Collaborator

huafu commented Oct 21, 2018

That is a bug I was waiting for someone to report... I meant, I have it in mind, but never got the time to report neither fix.

Instead of just assuming package root to be in ../../, search for package root in every ancestor directory starting with ../.

Actually, not only. I meant, it's a bit more complex. For example in monorepo using yarn workspaces, the package.json of the related project (not the root one) is in ../../somewhere-usually-named-packages/the-package-name/package.json

@KSXGitHub
Copy link
Author

Actually, not only. I meant, it's a bit more complex. For example in monorepo using yarn workspaces, the package.json of the related project (not the root one) is in ../../somewhere-usually-named-packages/the-package-name/package.json

I think there're a few solutions to this:

  • Making package root configurable from jest.config.js.
  • Package root is whatever contains jest.config.js.

@huafu
Copy link
Collaborator

huafu commented Oct 21, 2018

Package root is whatever contains jest.config.js.

  • I have, and because I followed a tutoral so I am not the only one, all my config files in another dir:
config/
  jest.config.js
packages/
  a/
    package.json {scripts: {test: 'jest --config ../../config/jest.config.js'}}
  • You CANNOT know in all cases where is that jest.config.js from what Jest gives you as a transformer

Making package root configurable from jest.config.js.

Best solution so far. When we cannot find the package.json, show a warning which explains about this config.

There is also a node package which allow to find that package.json, I can't remember its name, but I do remember it is written in the readme that it does not find it in 100% of the cases, even tho it's not just a lookup in parents

@dhl
Copy link

dhl commented Dec 20, 2018

Very interesting discussion here highlighting the nuances of the config lookup.

I wonder if the problem can be simplified by introducing some assumptions here. For example, according to TypeScript's documentation, tsconfig.json marks the root of a TypeScript project:

The presence of a tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project
Source

With the root of the project found, the jest.config.js file can be resolved by having the path looked up in the project root, or in a ts-jest config file or setting in package.json.

@KevinTCoughlin
Copy link

I'm also running into this warning similar to the above and @octogonz in #852. Has there been any resolution? Is this something that a contributor could fix?

jdhuntington pushed a commit to jdhuntington/ts-jest that referenced this issue Mar 1, 2019
Updates loading of package.json to allow specifying of file location or
entire contents in addition to existing behavior.
jdhuntington pushed a commit to jdhuntington/ts-jest that referenced this issue Mar 4, 2019
jdhuntington pushed a commit to jdhuntington/ts-jest that referenced this issue Mar 12, 2019
Document the package.json config option.
jdhuntington pushed a commit to jdhuntington/ts-jest that referenced this issue Mar 12, 2019
Document the package.json config option.
GeeWee pushed a commit that referenced this issue Mar 14, 2019
* feat(config): specify package.json location (#823)

* fix(docs): package.json config option (#823)

Document the package.json config option.
@lonix1
Copy link

lonix1 commented Apr 1, 2019

I see the fix is merged, but the docs are not showing the changes yet...

@mitch726
Copy link

This appears to have a fix in but the issue is still open. Did this fix actually resolve the issue for others?

@elliottsj
Copy link

The fix adds a packageJson option to explicitly define the path to your package.json file, so ts-jest doesn't need to automatically find it, therefore this warning is avoided

ts-jest[config] (WARN) Unable to find the root of the project where ts-jest has been installed.

In my project, I added this to my jest.config.js and the warning is gone:

globals: {
  'ts-jest': {
    packageJson: 'package.json',
  },
},

@ahnpnl
Copy link
Collaborator

ahnpnl commented Oct 27, 2019

Closed as already provided a way to config path to package.json

@flowyfulwolf
Copy link

I'm still getting the warning, does anybody has an idea why?
"jest": { "verbose": true, "collectCoverage": true, "preset": "ts-jest", "globals": { "ts-jest": { "packageJson": "package.json" } },

@albertodiazdorado
Copy link

Hi @elliottsj , the packageJson option is not removed from ts-jest --> #2128

Any ideas on this?

CC @ahnpnl

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 10, 2021

it is removed in v27

@albertodiazdorado
Copy link

Hi @ahnpnl , do you have any idea about how to get rid of this warning in v27?

ts-jest[config] (WARN) Unable to find the root of the project where ts-jest has been installed.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 10, 2021

if you use ts-jest 27, that warning should not be there anymore because v27 we have removed it.

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

No branches or pull requests

10 participants