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

TSC resolves symlinks but ts-jest does not #825

Closed
KSXGitHub opened this issue Oct 23, 2018 · 13 comments
Closed

TSC resolves symlinks but ts-jest does not #825

KSXGitHub opened this issue Oct 23, 2018 · 13 comments

Comments

@KSXGitHub
Copy link

Issue

TypeScript command resolves symlinked modules but ts-jest does not.

Steps to reproduce

I have a node_modules structure looks like this (generated by using pnpm as package manager):

+ index.ts
+ node_modules/
    + bar (symlink) → .registry.npmjs.org/1.2.3/node_modules/bar
    + .registry.npmjs.org/1.2.3/node_modules/
      + foo/index.ts
      + bar/index.ts

<root>/index.ts:

import Bar from 'bar'

export default class Root extends Bar {
  getData () {
    return this.data // 'protected data' from 'class Foo' of package 'foo'
  }
}

<root>/node_modules/.registry.npmjs.org/1.2.3/node_modules/foo/index.ts:

import Foo from 'foo'
export default class Bar extends Foo {}

<root>/node_modules/.registry.npmjs.org/1.2.3/node_modules/bar/index.ts:

export default class Foo {
  protected data = 123
}

Expected behavior

No errors

Current behavior

error TS2339: Property 'data' does not exist

This is travis log in my project: https://travis-ci.org/ksxnodemodules/external-dependencies/builds/444756379

@huafu
Copy link
Collaborator

huafu commented Oct 23, 2018

@KSXGitHub I believe this is not related to symlinks. What is your tsconfig and jest config?

@KSXGitHub
Copy link
Author

KSXGitHub commented Oct 23, 2018

@huafu

What is your tsconfig and jest config?

tsconfig.json

jest.config.js

NOTES:

  • The two files are not in the same directory.
  • Jest, ts-jest and typescript is installed in a subdirectory (<root>/tools/jest).
  • I use commands from the subdirectories to compile/test the whole monorepo.

I believe this is not related to symlinks

It was fine with flat node_modules (direct and indirect dependencies are in the same level). But when I switch most of my packages to pnpm's strict nested node_modules, ts-jest yields errors while TSC does not. The only explanation I could think of is that TSC resolves symlinks before compiling them while ts-jest does not.

@huafu
Copy link
Collaborator

huafu commented Oct 23, 2018

Looking at your repo, those are weird linkage going on lol

Anyway, where is the advanced-set-mutable-multi-key package? Sounds like this is the one containing the MultiKeySet which must declare data property since it is not declared in the RelationshipSet type.

@huafu
Copy link
Collaborator

huafu commented Oct 23, 2018

@KSXGitHub if you are sure it's related to symlinks, then I think this issue needs to be moved to jest. As a jest transformer, we are given a file path and then using it to read the file's content using system reads such as fs.readFileSync.

THe only thing I see that could come in to mess up everything is the cache, so you should try to see if you still have the issue when you run the tests with --no-cache.

@KSXGitHub
Copy link
Author

As a jest transformer, we are given a file path and then using it to read the file's content using system reads such as fs.readFileSync.

Can you just fs.realpath() on that file path?

THe only thing I see that could come in to mess up everything is the cache, so you should try to see if you still have the issue when you run the tests with --no-cache.

This fails even in CI.

@huafu
Copy link
Collaborator

huafu commented Oct 23, 2018

Can you just fs.realpath() on that file path?

this won't change anything, and I forgot to mention that we actually do not read the file as jest gives us its content as well

As asked there #825 (comment) where can I find the source of advanced-set-mutable-multi-key package, I need to see the signature of MultiKeySet

@KSXGitHub
Copy link
Author

As asked there #825 (comment) where can I find the source of advanced-set-mutable-multi-key package, I need to see the signature of MultiKeySet

advanced-set-mutable-multi-key/index.ts

advanced-set-base/index.ts

@huafu
Copy link
Collaborator

huafu commented Oct 23, 2018

I'll need to have some more time to clone your repo and check locally... but I'm pretty sure it's not related to ts-jest

@KSXGitHub
Copy link
Author

KSXGitHub commented Oct 23, 2018

You may need to use pnpm (in place of yarn/npm) as well to produce the same layout.
Read .travis.yml for further instruction.

@cortopy
Copy link

cortopy commented Jan 14, 2019

I think this can be closed. Works for me probably because of pnpm/pnpm#1007

@KSXGitHub
Copy link
Author

KSXGitHub commented Jan 14, 2019

I think this can be closed. Works for me probably because of pnpm/pnpm#1007

The test works just fine, but it prints warning, corrupting terminal output, which is what this issue is about

@GeeWee
Copy link
Collaborator

GeeWee commented Feb 16, 2019

Please provide a minimal reproducible repository. There seems to be a whole slew of issues in relation to pnpm.

@dashmug
Copy link

dashmug commented Mar 18, 2019

This happens when running jest (with ts-jest) inside AWS CodeBuild when using CodeBuild's caching feature.

The way CodeBuild's caching work is that they cache node_modules between builds. At the beginning of a build, CodeBuild symlinks the cache directory in your project's node_modules. I think this is similar to pnpm's symlinking feature.

Also, this does not happen on my local machine using yarn.

kulshekhar added a commit that referenced this issue Aug 19, 2019
fix: #825 handle symlinked modules (ala pnpm) correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants