Skip to content

tsc -b produces different outcomes with same inputs (using project references & typescript@beta) #33770

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

Closed
kiprasmel opened this issue Oct 2, 2019 · 1 comment
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@kiprasmel
Copy link

kiprasmel commented Oct 2, 2019

TypeScript Version: typescript@beta (3.7.0-beta)

Search Terms:
Project references, compilation fails, tsc -b, yarn tsc -b, yarn workspaces, monorepo

Context:

I've got a similar project set up as https://github.com/RyanCavanaugh/learn-a. Mine also uses yarn-workspaces.

I want to be able to run tsc -b (global typescript installation) and/or tsc -b -w (local typescript installation, defined in package.json). I've tried both.

Expected behavior:
I'm able to consistently get the same output with the same inputs.

Actual behavior:
With the same inputs (source files) the compiler sometimes successfully compiles, and sometimes it fails with errors:

<filename>:69:420 - error TS2307: Cannot find module '@my-project/local-package'.

I've had a higher success rate with the global tsc -b rather than the local yarn run tsc -b by the way. It seems that if one's failing, removing the generated dist files and running the other will work. Strange.

Playground Link:

https://github.com/sarpik/turbo-schedule

git clone https://github.com/sarpik/turbo-schedule.git
# or:  git clone [email protected]:sarpik/turbo-schedule.git
cd turbo-schedule
yarn install

yarn global add [email protected]

tsc -b                  # sometimes works, sometimes doesn't
yarn run purge:build    # clean up
yarn run tsc -b         # sometimes works, sometimes doesn't

Related Issues:
#32028 (comment)
#20148
#26867
#26689

Edit:

I thought this was a problem between tsc -b and yarn run tsc -b, but it isn't - running the compiler either way sometimes fails and sometimes succeeds.

Could this be with my purge:build script? It just removes the ./client/build and ./*/dist, making the project available to be cleanly rebuilt.

Edit v2:

After moving all of my projects' typescript dependency from devDependencies to dependencies, the issue seems to occur a little rarer, but it still happens quite a lot.

@kiprasmel kiprasmel changed the title Running yarn tsc -b with project references fails, tsc -b succeeds - differences with global & local tsc installation tsc -b produces different outcomes with same inputs (using project references & typescript@beta) Oct 2, 2019
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Oct 17, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.8.0 milestone Oct 17, 2019
@kiprasmel
Copy link
Author

kiprasmel commented Oct 22, 2019

Update - I found what was wrong:

Somehow I had typescript@dev (Version 3.7.0-dev.20191010) in my node_modules. I found this with ./node_modules/.bin/tsc -v.

Re-running yarn add typescript@beta solved the issue.

I don't know how this happened or why - I've never added typescript@dev, only typescript@beta.

Edit:

It was obviously also saved in my yarn.lock. Once again, yarn add typescript@beta solved this.

typescript@^3.7.0-beta:
  version "3.7.0-dev.20191010"
  resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.0-dev.20191010.tgz#e2a8d42b0586f129597543b2694a304335c6cc94"
  integrity sha512-mVo3R9cDL9OAts6dMPStwICr188gfojYgdUlzNZBj41/HCONtRdwoAe9FTNNHiTyQeCRJHg9O9udwn+dYWutJw==

Edit 2:

I was also using a very bad purge script:

"purge:build": "rimraf ./**/dist"

which would also affect the ./node_modules/**/dist folders, which is terrible xD

I found that this would also cause an issue (duh)

The correct script would be

"purge:build": "rimraf ./*/dist"

assuming that you're not inside node_modules directory..


Thank you for your time & help:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants