Skip to content

Instantly share code, notes, and snippets.

@dbarjs
Last active July 6, 2023 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbarjs/c9d8d4b4e19bffcf3aa3dc041d2993f6 to your computer and use it in GitHub Desktop.
Save dbarjs/c9d8d4b4e19bffcf3aa3dc041d2993f6 to your computer and use it in GitHub Desktop.
Fix for absolute paths on builded tsconfig.json on Nuxt 3.6.0.
import { relative, resolve } from 'node:path';
export default defineNuxtConfig({
hooks: {
'prepare:types': ({ tsConfig }) => {
if (!tsConfig?.compilerOptions?.paths) {
return;
}
const rootDir = process.cwd();
const nuxtDirectory = resolve(rootDir, '.nuxt');
const baseUrl = relative(nuxtDirectory, rootDir);
const relativePaths = Object.entries<string[]>(
tsConfig.compilerOptions.paths,
).reduce<Record<string, string[]>>((paths, [pattern, locations]) => {
if (Array.isArray(locations)) {
paths[pattern] = locations.map((location) => {
return relative(rootDir, location);
});
}
return paths;
}, {});
tsConfig.compilerOptions.baseUrl = baseUrl;
tsConfig.compilerOptions.paths = relativePaths;
},
},
});
// Generated by nuxi
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"jsx": "preserve",
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"skipLibCheck": true,
"strict": true,
"allowJs": true,
"baseUrl": "..",
"noEmit": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"types": [
"node"
],
"paths": {
"~": [
""
],
"~/*": [
"*"
],
"@": [
""
],
"@/*": [
"*"
],
"~~": [
""
],
"~~/*": [
"*"
],
"@@": [
""
],
"@@/*": [
"*"
],
"assets": [
"assets"
],
"public": [
"public"
],
"public/*": [
"public/*"
],
"#app": [
"../../node_modules/nuxt/dist/app"
],
"#app/*": [
"../../node_modules/nuxt/dist/app/*"
],
"vue-demi": [
"../../node_modules/nuxt/dist/app/compat/vue-demi"
],
"#vue-router": [
".nuxt/vue-router"
],
"#imports": [
".nuxt/imports"
],
"#build": [
".nuxt"
],
"#build/*": [
".nuxt/*"
],
"#components": [
"/home/dbarjs/_dev/flux-jobboard/apps/job-preferences/.nuxt/components"
]
}
},
"include": [
"./nuxt.d.ts",
"../**/*"
],
"exclude": [
"../dist",
"../.output"
]
}
// Generated by nuxi
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"jsx": "preserve",
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"skipLibCheck": true,
"strict": true,
"allowJs": true,
"baseUrl": "/home/app/packages/web",
"noEmit": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"types": [
"node"
],
"paths": {
"~": [
"/home/app/packages/web"
],
"~/*": [
"/home/app/packages/web/*"
],
"@": [
"/home/app/packages/web"
],
"@/*": [
"/home/app/packages/web/*"
],
"~~": [
"/home/app/packages/web"
],
"~~/*": [
"/home/app/packages/web/*"
],
"@@": [
"/home/app/packages/web"
],
"@@/*": [
"/home/app/packages/web/*"
],
"assets": [
"/home/app/packages/web/assets"
],
"public": [
"/home/app/packages/web/public"
],
"public/*": [
"/home/app/packages/web/public/*"
],
"#app": [
"/home/app/node_modules/nuxt/dist/app"
],
"#app/*": [
"/home/app/node_modules/nuxt/dist/app/*"
],
"vue-demi": [
"/home/app/node_modules/nuxt/dist/app/compat/vue-demi"
],
"#vue-router": [
"/home/app/packages/web/.nuxt/vue-router"
],
"#imports": [
"/home/app/packages/web/.nuxt/imports"
],
"#build": [
"/home/app/packages/web/.nuxt"
],
"#build/*": [
"/home/app/packages/web/.nuxt/*"
],
"#components": [
"/home/app/packages/web/.nuxt/components"
]
}
},
"include": [
"./nuxt.d.ts",
"../**/*"
],
"exclude": [
"../dist",
"../.output"
]
}
@dbarjs
Copy link
Author

dbarjs commented Jul 6, 2023

Related issue: nuxt/nuxt#21827

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