Remove default aliases
Describe the feature
Right now, default path aliases like ~ or @@ can't be deleted, only overridden.
Would it make sense to alter the code so setting them to a falsy value like undefined or '' in the nuxt.config.ts would remove them entirely?
Related: https://github.com/nuxt/framework/discussions/7274
Additional information
- [X] Would you be willing to help implement this feature?
- [ ] Could this feature be implemented as a module?
Final checks
- [X] Read the contribution guide.
- [X] Check existing discussions and issues.
I would be happy to continue discussion why this is needed. Such customization for built-ins can possibly break many things like modules or config depending on aloases.
possibly break many things like modules or config depending on aliases
this feature would not change defaults nor prevent someone from manually setting correct aliases. but it would allow enforcing consistency so a project codebase isn't a mix of all of them (that's the "problem" i currently have). we might want to only use ~ but vscode suggestions keep adding ~~ because it appears first in the tsconfig paths.
i don't see an issue with this if you state in documentation that disabling defaults might break things. nobody but the users tinkering with default aliases will be affected.
rc10
For my use case, we have a utility package in monorepo. After I extend the tsconfig in nuxt.config.ts, I was expecting I vscode to recommend the autocomplete with the correct alias. Instead ~~ alias took precedence.


If I manually change the order (move '~~,~ and @' to last), or remove the alias in .nuxt/tsconfig.json, the alias is correct.

If what you want to do is remove it from autocomplete then you can do this:
export default defineNuxtConfig({
hooks: {
'prepare:types' ({ tsConfig }) {
const aliasesToRemoveFromAutocomplete = ['~~', '~~/*']
for (const alias of aliasesToRemoveFromAutocomplete) {
if (tsConfig.compilerOptions.paths[alias]) {
delete tsConfig.compilerOptions.paths[alias]
}
}
}
}
})
i want change alias default value to :
alias: {
'~': '/<rootDir>',
'@': '/<rootDir>',
assets: '/<rootDir>/assets',
public: '/<rootDir>/public',
},
components: {
dirs: [
{ path: '~/components/basic/', prefix: 'y' },
{ path: '~/components/others/', prefix: 'y' },
{ path: '~/components/form/', prefix: 'y' },
{ path: '~/components/navigation/', prefix: 'y' },
{ path: '~/components/data/', prefix: 'y' },
{ path: '~/components/business/', prefix: 'y' },
{ path: '~/components/feedback/', prefix: 'y' },
],
},
but tsconfig.json in .nuxt still have~~
and show error:
WARN Components directory not found: /<rootDir>/components/basic 10:11:08
WARN Components directory not found: /<rootDir>/components/others 10:11:08
WARN Components directory not found: /<rootDir>/components/form 10:11:08
WARN Components directory not found: /<rootDir>/components/navigation 10:11:08
WARN Components directory not found: /<rootDir>/components/data 10:11:08
WARN Components directory not found: /<rootDir>/components/business 10:11:08
WARN Components directory not found: /<rootDir>/components/feedback 10:11:08
ERROR Cannot read properties of undefined (reading 'length') 10:11:13
✔ Nitro built in 3313 ms nitro 10:11:15
ℹ Vite client warmed up in 8817ms 10:11:18
[nuxt] [request error] [unhandled] [500] [vite-node] Failed to load /<rootDir>/assets/styles/theme.css
at ViteNodeRunner.directRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:180:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async ViteNodeRunner.cachedRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:128:12)
at async request (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:151:16)
at async virtual:nuxt:./.nuxt/css.mjs:1:238
at async ViteNodeRunner.directRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:251:5)
at async ViteNodeRunner.cachedRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:128:12)
at async request (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:151:16)
at async ./node_modules/.pnpm/[email protected]_z4bbprzjrhnsfa24uvmcbu7f5q/node_modules/nuxt/dist/app/entry.mjs:9:31
at async ViteNodeRunner.directRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:251:5)
[nuxt] [request error] [unhandled] [500] [vite-node] Failed to load /<rootDir>/assets/styles/theme.css
at ViteNodeRunner.directRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:180:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async ViteNodeRunner.cachedRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:128:12)
at async request (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:151:16)
at async virtual:nuxt:./.nuxt/css.mjs:1:238
at async ViteNodeRunner.directRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:251:5)
at async ViteNodeRunner.cachedRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:128:12)
at async request (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:151:16)
at async ./node_modules/.pnpm/[email protected]_z4bbprzjrhnsfa24uvmcbu7f5q/node_modules/nuxt/dist/app/entry.mjs:9:31
at async ViteNodeRunner.directRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:251:5)
<rootDir> isn't a magic string. It needs to be the actual path to your root directory.