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

[Bug] vscode tsserver crashed when using typescript in a monorepo #1189

Closed
missing1984 opened this issue Apr 12, 2020 · 6 comments
Closed

[Bug] vscode tsserver crashed when using typescript in a monorepo #1189

missing1984 opened this issue Apr 12, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@missing1984
Copy link
Contributor

  • [] I'd be willing to implement a fix

Describe the bug

vscode tsserver crashed when having tsconfig.json and typescript installed in a monorepo package (not project root)

error trace.

    Cannot destructure property 'name' of 'object null' as it is null.

    TypeError: Cannot destructure property 'name' of 'object null' as it is null.
        at getPackageInformation (/Users/mluo/workspace/gitlab/monorepo/projects/example/.pnp.js:30630:5)
        at Object.getPackageInformation (/Users/mluo/workspace/gitlab/monorepo/projects/example/.pnp.js:30973:20)
        at getPnpTypeRoots (/Users/mluo/workspace/gitlab/monorepo/projects/example/.yarn/cache/typescript-patch-50eb28f081-2.zip/node_modules/typescript/lib/tsserver.js:28763:42)

To Reproduce

I've created a minimal project that can reproduce this issue.

tsserver_crash.zip

switch to use workspace tsc will soon found it crashed.

Environment if relevant (please complete the following information):

  • OS: [e.g. OSX, Linux, Windows, ...]
    OSX
  • Node version [e.g. 8.15.0, 10.15.1, ...]
node -v
v10.16.2
  • Yarn version [e.g. 2.0.0-rc1, ...]
yarn -v
2.0.0-rc.31

Additional context

Looks like tsc assume tsconfig.json and typescript installed at repo root?

@missing1984 missing1984 added the bug Something isn't working label Apr 12, 2020
@missing1984
Copy link
Contributor Author

Also, In my case yarn root is not the repo root.

For example:

.vscode
web/.yarnrc.yml
web/.pnp.js

@missing1984
Copy link
Contributor Author

@arcanis looks like you maintain a typescript patch for this. Can you share some light? I would be happy to help out whatever I can.

@ojkelly
Copy link
Contributor

ojkelly commented Apr 21, 2020

Theres a linked issue in the tsc repo microsoft/TypeScript#37477

I'm also getting this, but my yarn is the root of the repo.

@Seally
Copy link

Seally commented Apr 21, 2020

I believe the relevant patches are linked to this PR: microsoft/TypeScript#35206

@arcanis
Copy link
Member

arcanis commented Apr 21, 2020

The problem is that the TS type roots are supposed to be loaded based on the current directory. In the case you describe, since the repo root isn't the Yarn root, the cwd TS is spawned with isn't part of the project, causing the error you see.

For what it's worth, my own solution is to always configure the editor-typescript at the root of the repository, and write small tsconfig.json in each workspace that extend the editor one. That requires to make Yarn the repo root, however.

@arcanis arcanis mentioned this issue Apr 22, 2020
@missing1984
Copy link
Contributor Author

Verified. One constraint is our sdk plugin require typescript prettier and eslint declared in yarn root package.json

If you have those packages declare in child workspaces it's not gonna work. I am going to update our docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants