Show warning when the user sets path aliases that look like npm package imports
Description
- New documentation page explaining why. (And update https://vike.dev/path-aliases.)
- New setting to suppress the warning: https://github.com/vikejs/vike/issues/1499.
- The warning should apply only to path aliases defined by the user. (Not those defined by Vite plugins since the user usually has no control over these path aliases.)
my vue/vite spa uses the @ convention for paths from /src/* . the alias is defined in vite.config.js.
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
},
If I try and import using this alias from +config.js
import webSocketPlugin from '@/stores/plugins/webSocketPlugin'
I get the error ✘ [ERROR] Could not resolve "@/stores/plugins/webSocketPlugin" [plugin vike-esbuild].
--
I've also tried using #root instead @ but got the same error. I can get it to import with a relative path, but webSocketPlugin includes a bunch of imports with @ that then fail. Any ideas on how to use @ paths?
@pketh Would whitelisting any import path that starts with @/ do the trick for you (edit: it's already the case)? We can whitelist them because @/some/path cannot be an npm package (I just tried and npm doesn't allow organization names to start with /).
As for the error, minimal reproduction welcome.
As for the error, minimal reproduction welcome.
Actually, I guess you're trying to use Vite aliases in Vike config files which isn't supported until Vite uses Rolldown, see https://github.com/vikejs/vike/issues/1547.