question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setPublicPath sets wrong path when using mix.js()

See original GitHub issue
  • Laravel Mix Version: 1.0.7
  • Node Version: 6.10.2
  • NPM Version: 5.0.4
  • OS: Windows 7 Ultimate x64

Description:

image

I’m trying to relocate my assets to an ‘assets’ subfolder inside /public. The mix-manifest.json gets created in the correct location and mix.less() outputs my CSS files and updates the reference in the manifest with the correct location as well. The mix.js() method however behaves strangely, as you can see in the screenshot.

I’m using the simplest possible setup to demonstrate this - a fresh installation of Laravel and npm install. I have tried adding and removing slashes all over the place, but to no avail.

Steps To Reproduce:

  1. Edit the webpack.mix.js file with the following:
mix.setPublicPath('public/assets');
mix.js('resources/assets/js/index.js', 'js');
mix.less('resources/assets/less/index.less', 'css');
  1. npm run dev

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:13

github_iconTop GitHub Comments

9reactions
TopFuelcommented, Sep 6, 2017
  • Laravel Mix Version: 1.2.2
  • OS: Windows 10 Creators Update x64

Can confirm that using path.normalize on mix.setPublicPath fixes the issue where I needed to change from:

mix.setPublicPath('../public');
mix.js('resources/assets/js/app.js', '../public/js/app.js'); // or 'js/app.js'

to:

mix.setPublicPath('..\\public');
mix.js('resources/assets/js/app.js', '..\\public/js/app.js'); // or 'js/app.js'

for it to work correctly, or it would freeze at 95% emitting on the npm run development command, and outputs this to the mix-manifest.json:

{
    "/E:/projects/test-project/public/E:/projects/test-project/public/js/app.js": "/E:/projects/test-project/public/E:/projects/test-project/public/js/app.js"
}

But adding path.normalize fixes it:

mix.setPublicPath(path.normalize('../public'));
mix.js('resources/assets/js/app.js', '../public/js/app.js'); // or 'js/app.js'

mix-manifest.json:

{
    "/js/app.js": "/js/app.js"
}
8reactions
gabrieldasilvacommented, Jul 10, 2017

Hey! I’m having some throubles with this too. Actually I have a project from tree weeks ago with last mix version at that moment (0.*) and the public path was working fine. Today I start a new project and I realize that already comes with the Mix 1.1.1.

So, I basically copy / paste my webpack.mix and this issue appears…

My public path is somehing like ‘public/assets/www/…’ so then I have website folders for css, images, fonts, js etc…

I think I figure it out by using the path.normalize inside setPublicPath like this:

mix.setPublicPath(path.normalize('public/assets/www/'));

but I want to know if now this is the way to use the custom path.

My configuration its actually the same that @omnichronous uses…

Btw, I’m using Windows 10 x64.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setPublicPath sets wrong path when using mix.js() · Issue #960
I'm trying to relocate my assets to an 'assets' subfolder inside /public. The mix-manifest.json gets created in the correct location and mix.
Read more >
Frequently Asked Questions | Laravel Mix Documentation
Just be sure to explicitly set the path to your project's public or dist directory, like so: mix.setPublicPath('dist');. This tells Mix the basic...
Read more >
Laravel mix.js() using absolute path after publicPath is set
Is this an issue with mix or am I doing something wrong? I only have a problem with mix.js() , everything else works...
Read more >
How to use the laravel-mix.setPublicPath function in ... - Snyk
setPublicPath examples, based on popular ways it is used in public projects. ... const mix = require("laravel-mix") const path = require("path") const ...
Read more >
Laravel Mix is compiling files to a wrong directory - Laracasts
Hey, I am using Laravel Mix for the first time in a stand-alone project and I am facing a problem I can't solve....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found