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

Monorepo: caching logic fails when using yarn workspace #232

Closed
ael-g opened this issue Jun 16, 2020 · 3 comments
Closed

Monorepo: caching logic fails when using yarn workspace #232

ael-g opened this issue Jun 16, 2020 · 3 comments
Labels
kind: bug Something isn't working properly problem: needs more info This issue needs more information in order to handle it problem: no repro No reproduction was provided (and have not tried to repro without one) problem: stale Issue has not been responded to in some time scope: cache Related to the cache solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc)

Comments

@ael-g
Copy link

ael-g commented Jun 16, 2020

Hi,
I have a monorepo managed with lerna and yarn, I started without using yarn workspaces, everything built fine with tsdx.
When I enabled yarn workspaces, juste changing:

# lerna.json
+ "useWorkspaces": true,

# package.json
+  "workspaces": {
+    "packages": [
+      "packages/*"
+    ]
+  },

None of my packages build anymore and are failing with this error:

yarn run v1.12.3
$ tsdx build --target node --format cjs
✓ Creating entry file 4.1 secs
(typescript) Error: ENOENT: no such file or directory, rename './.rts2_cache_cjs/rpt2_121e96229b238ff988af731a4cd7041299f06b93/code/cache_' -> './.rts2_cache_cjs/rpt2_121e96229b238ff988af731a4cd7041299f06b93/code/cache'
Error: ENOENT: no such file or directory, rename './.rts2_cache_cjs/rpt2_121e96229b238ff988af731a4cd7041299f06b93/code/cache_' -> './.rts2_cache_cjs/rpt2_121e96229b238ff988af731a4cd7041299f06b93/code/cache'
    at Object.renameSync (fs.js:643:3)
    at RollingCache.roll (...node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23992:12)
    at TsCache.done (...node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:24805:24)
    at Object._ongenerate (...node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:26803:21)
    at Object.generateBundle (...node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:26779:18)
    at ...node_modules/rollup/dist/shared/node-entry.js:13117:25

Here are my conf files:
tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "baseUrl": ".",
    "types": [
      "jest"
    ],
    "paths": {
      "src/*": [
        "../*"
      ]
    },
    "typeRoots": [
      "./node_modules/@types"
    ],
    "skipLibCheck": true
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

verbosity 3

rpt2: typescript version: 3.6.4
rpt2: tslib version: 1.9.3
rpt2: rollup version: 1.32.1
rpt2: rollup-plugin-typescript2 version: 0.21.2
rpt2: plugin options:
{
    "typescript": "version 3.6.4",
    "verbosity": 3,
    "cacheRoot": "./.rts2_cache_cjs",
    "tsconfigDefaults": {
        "compilerOptions": {
            "sourceMap": true,
            "declaration": true,
            "jsx": "react"
        }
    },
    "tsconfigOverride": {
        "compilerOptions": {
            "target": "esnext"
        }
    },
    "check": true,
    "clean": false,
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "transformers": [],
    "objectHashIgnoreUnknownHack": false
}
rpt2: rollup config:
{
    "chunkGroupingSize": 5000,
    "experimentalCacheExpiry": 10,
    "inlineDynamicImports": false,
    "input": "***/src/index.ts",
    "perf": false,
    "plugins": [
        {
            "name": "node-resolve"
        },
        {
            "name": "json"
        },
        {},
        {
            "name": "rpt2"
        },
        {
            "name": "babel"
        },
        {
            "name": "replace"
        },
        {
            "name": "sourcemaps"
        }
    ],
    "strictDeprecations": false
}
rpt2: tsconfig path: ***/tsconfig.json

I tried with version 0.27.1 of the plugin but same error.
And I see a large proportion of cache miss during the build.

Setting clean: true in the plugin conf fix this issue but I run into other weird issues about types which I can describe if needed, but I guess it should work without setting clean: true anyway.

Thanks for your help!

@agilgur5
Copy link
Collaborator

Not totally sure what's going on here, but seems like you're using an old version version of TSDX based on the ./.rts2_cache_cjs/ path that I changed back in November: jaredpalmer/tsdx#329

@agilgur5 agilgur5 added problem: stale Issue has not been responded to in some time problem: needs more info This issue needs more information in order to handle it problem: no repro No reproduction was provided (and have not tried to repro without one) labels Apr 24, 2022
@agilgur5
Copy link
Collaborator

agilgur5 commented Apr 25, 2022

Closing this as stale as no further response was given by OP and versions were outdated.

It's also very possible that the move to workspaces actually changed the location of the cache and caused this issue, so clean: true may in fact be temporarily required, if not more (e.g. cleaning npm cache etc). In any case, difficult to glean any more without more information or a proper minimal reproduction

@agilgur5 agilgur5 added solution: workaround available There is a workaround available for this issue topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc) labels Apr 25, 2022
@agilgur5 agilgur5 added the scope: cache Related to the cache label May 8, 2022
@agilgur5 agilgur5 added kind: bug Something isn't working properly solution: duplicate This issue or pull request already exists topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc) and removed topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc) labels Jun 8, 2022
@agilgur5
Copy link
Collaborator

agilgur5 commented Jun 8, 2022

Took a look at this again and thought it sounded familiar... and yep, this seems to duplicate a few issues: jaredpalmer/tsdx#892 and jaredpalmer/tsdx#888, which were fixed by jaredpalmer/tsdx#896 downstream and here in #243.

#243 was merged ~3 months after this issue was created.

Per those issues/PRs, I don't think this has anything to do with monorepos / Yarn workspaces per se, it seems to have been that the cache dir may have sometimes been deleted due to some race condition. Moving to workspaces could have changed the dir or otherwise required cleaning the cache (per above), or it was just coincidence that you hit it after as it's a race condition.

Repository owner locked as resolved and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: bug Something isn't working properly problem: needs more info This issue needs more information in order to handle it problem: no repro No reproduction was provided (and have not tried to repro without one) problem: stale Issue has not been responded to in some time scope: cache Related to the cache solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc)
Projects
None yet
Development

No branches or pull requests

2 participants