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

Build failed, error thrown #3345

Closed
krzar opened this issue Jun 30, 2023 · 5 comments · Fixed by #3556
Closed

Build failed, error thrown #3345

krzar opened this issue Jun 30, 2023 · 5 comments · Fixed by #3556

Comments

@krzar
Copy link

krzar commented Jun 30, 2023

When i'm trying to build my application with vue-tsc --noEmit && vite build --emptyOutDir I'm getting this error all the time:

/var/www/frontend/node_modules/vue-tsc/bin/vue-tsc.js:64
                        throw err;
                        ^

Error: Debug Failure. False expression: Paths must either both be absolute or both be relative
    at getRelativePathFromDirectory (/var/www/frontend/node_modules/typescript/lib/tsc.js:5637:9)
    at relativeToBuildInfo (/var/www/frontend/node_modules/typescript/lib/tsc.js:117963:38)
    at toFileId (/var/www/frontend/node_modules/typescript/lib/tsc.js:117968:22)
    at arrayFrom (/var/www/frontend/node_modules/typescript/lib/tsc.js:715:24)
    at toFileIdListId (/var/www/frontend/node_modules/typescript/lib/tsc.js:117974:21)
    at /var/www/frontend/node_modules/typescript/lib/tsc.js:117897:32
    at mapDefined (/var/www/frontend/node_modules/typescript/lib/tsc.js:300:22)
    at getBuildInfo2 (/var/www/frontend/node_modules/typescript/lib/tsc.js:117893:26)
    at newProgram.getBuildInfo (/var/www/frontend/node_modules/typescript/lib/tsc.js:118145:41)
    at Object.getBuildInfo (/var/www/frontend/node_modules/typescript/lib/typescript.js:117443:70)

Node.js v18.16.1
error Command failed with exit code 1.

I've this error before, but usually running yarn upgrade helped, now it doesn't even help (probably no package is getting updated). I was trying to remove node_modules and yarn.lock but it's still not working.

@so1ve
Copy link
Member

so1ve commented Jul 3, 2023

Could you please provide a minimal reproduction?

@so1ve so1ve added the need info label Jul 3, 2023
@krzar
Copy link
Author

krzar commented Jul 3, 2023

Unfortunately, I don't know what is causing the problem, but I managed to solve it for now by reverting to an older yarn. lock in my project. I suspect that some package is conflicting, but I'm not sure which one exactly.

@BenShelton
Copy link

BenShelton commented Jul 5, 2023

Reproduction

Seems related to #2622 which has been closed, but this is still happening on latest vue-tsc and typescript versions.

Here is a reproduction: https://codesandbox.io/p/sandbox/vue-tsc-debug-failure-n6l43n?welcome=true

If you run the tsc task in that repro the error happens. There is a simple typescript error in App.vue, but instead of warning about that it throws this error.

This seems to be something to do with either composite or incremental, it doesn't happen the first time vue-tsc is run, but the second time it does. I assume reading from the tsbuildinfo is where the actual error happens but I'm not that familiar with TS internals.

Workaround

Currently we're using a pnpm patch to get around this:

diff --git a/bin/vue-tsc.js b/bin/vue-tsc.js
--- a/bin/vue-tsc.js
+++ b/bin/vue-tsc.js
@@ -37,6 +37,9 @@ fs.readFileSync = (...args) => {
 					.map(file => file.replace(/\.vue\.(j|t)sx?$/i, '.vue'));\n` + s
 			);
 		}
+		if (semver.gte(tsPkg.version, '5.1.3')) {
+			tryReplace(`Debug.assert(getRootLength(fromDirectory) > 0 === getRootLength(to) > 0, "Paths must either both be absolute or both be relative");`, ``);
+		}
 
 		return tsc;

@maspetsberger
Copy link

From what I can tell, the problem stems from the filtering of filenames here:

.filter(file => !file.toLowerCase().includes('__vls_'))

This removes certain filenames from the internal list, which then clashes later when tsc is building all the reference and export maps, since the .tsbuildinfo file stores all references by position in this array - when things get removed/added this just doesn't align any longer.

At least with composite: true, I'm already having the above error with typescript: 5.0.4, albeit only at the third run or so; same for typescript: 5.1.6.

When I remove the line above, i.e. do not filter out the VLS files, then the alignment seems to match again and the error goes away:

diff --git a/packages/vue-tsc/bin/vue-tsc.js b/packages/vue-tsc/bin/vue-tsc.js
index f0c7776f..fc40dd93 100755
--- a/packages/vue-tsc/bin/vue-tsc.js
+++ b/packages/vue-tsc/bin/vue-tsc.js
@@ -33,7 +33,6 @@ fs.readFileSync = (...args) => {
                        tryReplace(
                                `return createBuilderProgramUsingProgramBuildInfo(buildInfo, buildInfoPath, host);`,
                                s => `buildInfo.program.fileNames = buildInfo.program.fileNames
-                                       .filter(file => !file.toLowerCase().includes('__vls_'))
                                        .map(file => file.replace(/\.vue\.(j|t)sx?$/i, '.vue'));\n` + s
                        );
                }

In my case the referencedMap and the exportedModulesMap were aligned again with this change, so I'm inclined to say it's a change to the better. But all this string-replacing in the generated tsc code is beyond my comprehension...

@subframe7536
Copy link

same issue here, solve it with remove composite: true. the latest version that run without such error is v1.8.2

tsconfig.json

{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "include": [
    "env.d.ts",
    "src/**/*",
    "src/**/*.vue"
  ],
  "exclude": [
    "src/**/__tests__/*"
  ],
  "compilerOptions": {
-   "composite": true,
    "baseUrl": ".",
    "types": [
      "vite/client"
    ],
    "paths": {
      "@/*": [
        "./src/*"
      ],
    }
  }
}

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

Successfully merging a pull request may close this issue.

5 participants