Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

fylzero's avatar
Level 67

Webpack @ alias not working in app - only when running npm run prod on Forge

For some reason, that I can't seem to figure out, I am getting a swath of errors when deploying a specific app to Forge and running npm run prod in the deployment script.

ℹ Compiling Mix
✔ Mix: Compiled with some errors in 34.39s
ERROR in ./resources/js/Pages/Contacts/Create.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./resources/js/Pages/Contacts/Create.vue?vue&type=script&lang=js) 1:0-73
Module not found: Error: Can't resolve '@/Components/FormPhoneNumberInput.vue' in '/home/forge/{website url hidden}.com/resources/js/Pages/Contacts'

ERROR in ./resources/js/Pages/Contacts/Create.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./resources/js/Pages/Contacts/Create.vue?vue&type=script&lang=js) 2:0-51
Module not found: Error: Can't resolve '@/Components/FormInput.vue' in '/home/forge/{website url hidden}.com/resources/js/Pages/Contacts'

continues...   there are about 100 more of these errors.

I'm assuming my Webpack alias is not working but this is all using pretty standard Laravel boilerplate.

My webpack.mix.js

const mix = require('laravel-mix');

mix
    .js('resources/js/app.js', 'public/js').vue().extract()
    .postCss('resources/css/app.css', 'public/css', [
        require('postcss-import'),
        require('postcss-nested'),
        require('tailwindcss'),
    ])
    .webpackConfig(require('./webpack.config'));

if (mix.inProduction()) {
    mix.version();
}

My webpack.config.js

const path = require('path');

module.exports = {
    resolve: {
        alias: {
            '@': path.resolve('resources/js'),
        },
    },
};

My tailwind.config.js

const defaultTheme = require('tailwindcss/defaultTheme');
const colors = require('tailwindcss/colors');

module.exports = {
    content: [
        './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
        './storage/framework/views/*.php',
        './resources/views/**/*.blade.php',
        './resources/js/**/*.vue',
    ],

    theme: {
        extend: {
            fontFamily: {
                sans: ['Roboto', ...defaultTheme.fontFamily.sans],
            },
            screens: {
                'print': {'raw': 'print'},
            },
            colors: {
                green: colors.emerald,
                yellow: colors.amber,
                purple: colors.violet,
            },
        },
    },

    plugins: [],
};

If anyone has a thought, or something else I can try - please let me know. I'm totally stumped as to why this is happening. I have several other apps with the same config that don't seem to have a problem. Also, if I run npm run prod locally, it works without any issue. PHP versions are the same on local and Forge. I even went to far as to bump the Node and NPM version on Forge to match the latest on my system. Nothing seems to be resolving this.

I'm currently stuck having to run npm run prod before deploying which is just annoying.

0 likes
17 replies
Sinnbeck's avatar

Any chance that this component has different casing in the file? FormPhoneNumberInput. Like FormPhonenumberInput. Linux is case sensitive, and if you are running windows or mac locally, then this error would not occur there (only on forge)

fylzero's avatar
Level 67

@Sinnbeck Thank you for your response! I looked a bit and I don't see anything like that at a glance but I may have to just go through and audit every filename and import. This error displays about 180 times, I don't think I'd have made 180 typos (I would hope). This is a great idea to check this though. Please, let me know if there is anything else that comes to mind.

Sinnbeck's avatar

@fylzero My other idea is that your alias is somehow breaking. You can as a test, try and change just one of the failing imports to use a relative path instead

fylzero's avatar
Level 67

@Sinnbeck I'm about 99% sure that's what the problem is. I just can't think of how or why the alias would be broken. I feel like this is going to be a silly thing.

Also clearly has to be environment related.

fylzero's avatar
Level 67

@Sinnbeck I tried your suggestion and sent up a few relative paths - tested locally, worked fine... deploy failed with the same amount of errors. Maybe this is not the alias after all?

ERROR in ./resources/js/Layouts/NavLowerDesktop.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./resources/js/Layouts/NavLowerDesktop.vue?vue&type=script&lang=js) 2:0-58
Module not found: Error: Can't resolve '../Components/JumpToTicket.vue' in '/home/forge/{site url hidden}.com/resources/js/Layouts'

I guess this means imports are broken regardless of using an alias.

Sinnbeck's avatar

@fylzero Can you show how you are importing in "/home/forge/{site url hidden}.com/resources/js/Layouts" ?

fylzero's avatar
Level 67

@Sinnbeck Sure. Here is my NavLowerDesktop.vue file - shortened for the example.

<template>
    <nav class="hidden print:hidden lg:block fixed w-full z-30 bg-white drop-shadow-md" style="top: 48px">
        <div class="w-full max-w-screen-2xl mx-auto flex h-9 px-6">
            <div class="grow flex items-center">

                <JumpToTicket />
                
            </div>
        </div>
    </nav>
</template>

<script>
import JumpToTicket from '@/Components/JumpToTicket.vue';

export default {
    components: {
        JumpToTicket,
    },
};
</script>

Obviously a second ago I had that changed to the correct relative path:

import JumpToTicket from '../Components/JumpToTicket.vue';

Folder structure is:

- resources/js
    - Components
    - Layouts
Sinnbeck's avatar

@fylzero That looks fine.. And the file named JumpToTicket.vue? I assume that is named that and the components folder is with an uppercase C :)

fylzero's avatar
Level 67

@Sinnbeck It sure is (named correctly / capitalized identically). Messed up, right?

Sinnbeck's avatar

@fylzero Totally. Weird idea. Try removing .vue from the import, and let it handle that itself.

Also I assume this is vue3? And that you wipe the node_modules and reinstall npm packages on deploy?

fylzero's avatar
Level 67

@Sinnbeck I'll try that. Yes, using Vue 3. Here's my deploy script.

cd /home/forge/{project url hidden}.com
$FORGE_PHP artisan down --render="errors::503"
git reset --hard HEAD
git pull origin main
$FORGE_PHP artisan config:clear
$FORGE_PHP artisan route:clear
$FORGE_COMPOSER install --no-interaction --prefer-dist --optimize-autoloader

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

$FORGE_PHP artisan config:cache
$FORGE_PHP artisan route:cache
npm ci
# npm run production   // <--- THIS IS WHAT I CAN'T ENABLE/GET WORKING WITHOUT ERRORS
rm -rf node_modules

if [ -f artisan ]; then
    $FORGE_PHP artisan migrate --force
fi

$FORGE_PHP artisan up
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@fylzero That is indeed very very strange. Did you try logging into the server with ssh and checking if the files are actually there ?

fylzero's avatar
Level 67

@Sinnbeck Removing .vue from the imports didn't seem to make a difference. =T

fylzero's avatar
Level 67

@Sinnbeck I just did and BINGO!!!!! The components folder - at some point I changed the case and it kept the lower case version!!!!!! I think this will fix it, I just need to blow that away - brb - I'll let you know.

1 like
Sinnbeck's avatar

@fylzero Awesome. So it was indeed a casing issue. Interesting that git didnt change it :/

fylzero's avatar
Level 67

@Sinnbeck I've totally seen this before... the folder name just got sticky. I wound up having to use git mv twice to get it to hold.

Locally I just renamed the folder back to components then did git mv components comp the git mv comp Components

IT JUST DEPLOYED! THANK YOU! This one was driving me crazy!

Please or to participate in this conversation.