laravel-mix: Mix not resolving Alias using Mix.webpackConfig
- laravel-mix: “1.4.5”,
- Node v6.11.3
- NPM v3.10.10
- OS: OSX Sierra
Description:
Dependency not found error when trying to reference an alias from webpackConfig
mix.webpackConfig({
resolve: {
alias: {
Admin: path.resolve(__dirname, 'resources/admin')
}
}
});
Then trying to reference it as
import Validator from 'Admin/core/Validation/VeeValidation'
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (3 by maintainers)
It does not work for me still
Updated NPM, regarding the error output here it is
Note that in this case the alias is “@admin”
Set like this in webpack.mix.js
In case people found there way here via google like I did, one possibility is that you have an issue with case-sensitivity.
In my case,
npm run devwas working fine on OS X, but I didn’t realise that my git repo had bothComponentsandcomponentsdirectories pushed because I can only see one locally.Ubuntu / linux allows both these directories to co-exist which was causing my issue in production.
The solution is to make sure your import paths have the correct casing, and if you have a rogue file you can do this:
git mv resources/js/components/UserTableRow.vue resources/js/Components/UserTableRow.vue.Strange, after taking the weekend off i came back today and found out that it’s working now i must’ve done something wrong before.
Works fine, even with the string as key. No issue whatsoever. Thank you all for your help
I had the same issue in Laravel 8 and nothing was working… until I actually looked up the offical laravel-mix docs https://laravel-mix.com/docs/6.0/aliases
Looks like they changed the syntax.
The following is on the start of my webpack.mix.js:
And this actually works! I can load components like this:
@smtlk ha! just noticed this. Evidently I submitted this post before I finished. So that was an incomplete thought. I don’t remember what my thought was at the time, but that is usually how I use path.resolve. My first argument is the directory I want to start with, then I break up each nested directory into comma separated strings. However, I just installed a fresh laravel project and included the following in my mix file:
then in my app.js file, I utilized the alias:
and everything worked as I expected.
Are you exporting Validator correctly?
Sorry for the confusion.