Kisiara's avatar
Level 15

Cannot find or reference aliased modules using laravel mix's webpackConfig

I am using nwidart modules, laravel 5.6 and a Mac Pro Sierra.

For some unfortunate reason I just cant seem to get aliased modules on laravel mix to work at all.

I have a file ** /Modules/Core/Resources/assets/js**

export const core = {
    prefix: 'core',

    paths: [
        { url: 'redis', pagination: false },

        { url: 'modules', pagination: false },

        { url: 'genders', pagination: false },

        { url: 'relationships', pagination: false },
    ]
}

I decided to alias my references and followed this structure

webpack.mix.js

mix.webpackConfig({
    resolve: {
        extensions: ['.js'],
        alias: {
            '@core': path.resolve(__dirname, "Modules/Core/Resources/assets/js"),
        },
    },
});

In a file /resources/assets/js/store/paths.js, I then try to import the paths file from the aliased directory

/*
 * Define all the paths that will be accessed in the store
 */

import { core } from "@core/paths";

[core]
    .forEach( mod => {
        console.log(mod);
});

This code fails with an error

Uncaught Error: Cannot find module "@core/paths"

0 likes
1 reply
Kisiara's avatar
Level 15

Any help on this will be much appreciated.

Please or to participate in this conversation.