We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Expcetion: Resource '/assets/jquery/dist/jquery.min.js' does not have a valid source path

Hi,

I'm trying to get a minifed and combined version of my Javascript files with:

    $this->assets
        ->collection('footer')
        ->setTargetPath('final.js')
        ->addJs('/assets/jquery/dist/jquery.min.js', true, false)
        ->addJs('/assets/bootstrap/js/bootstrap.min.js', true, false)
        ->addJs('/common/js/luna.js', true)
        ->addJs('/user/js/custom.js', true)
        ->addJs('/assets/datatables/jquery.dataTables.min.js', true)
        ->addJs('/assets/datatables/dataTables.bootstrap.js', true)
        ->join(true)
        ->addFilter(new Jsmin());

I get this exception:

Exception: Resource '/assets/jquery/dist/jquery.min.js' does not have a valid source path

What should I change?

Thanks!



85.5k

try with full path to the file ?

but honestly i gave up on those and started using gulp. After all, npm is made for this kind of stuff

You should provide correct path.



14.4k

@Izo, yeah, gulp might be the solution.

@Wojciech Ślawski, I used this path the whole time before but without joining the files. Now wanted to take this further.



14.4k

Okay, I was able to resolve this with setting up the whole path. But now, the shown script "final.js" isn't created.

<script type="text/javascript" src="/final.js"></script>

Exception: Service 'view' wasn't found in the dependency injection container

Add view service to di ?

Problably you have application in subfolder, for example "localhost/yourapp/"

If i have right you should set BaseUri and StaticBaseUri. Example:


$di->set(
    'url',
    function () use ($config) {
        $url = new UrlResolver();
        $url->setBaseUri('/yourapp/');
        $url->setStaticBaseUri('https://localhost/yourapp/');
        return $url;
    }
);


14.4k

@Jurigag, it's defined. I work on my app pretty long now I used the assets manager the whole time. I just deciedet to make use of the join and minify function.

@Pwoszczyk, I can invoke my app through localhost:8004/. Maybe the port is the problem?

It depends of your web server.



14.4k
edited Nov '16

May one of you post a full example?

edited Nov '16

Apache2 on Ubuntu
/etc/apache2/ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80

<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


14.4k

@pwoszczyk, :) I meant a full working example within Phalcon assets. That would be nice!

edited Nov '16

Ok.

I locate JS files in myapp/public/vendor/*

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</IfModule>

public/.htaccess

AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

DI config in services.php

$di->set(
    'url',
    function () use ($config) {
        $url = new UrlResolver();
        $url->setBaseUri($config->application->path); // /myapp/
        $url->setStaticBaseUri($config->application->staticPath); // https://localhost/myapp/

        return $url;
    }
);

Use in volt

{% block js %}
    {% do assets.collection('vendor-js').addJs('vendor/jquery/dist/jquery.min.js') %}
    {% do assets.collection('vendor-js').addJs('vendor/bootstrap/dist/js/bootstrap.min.js') %}
{% endblock %}
{{ assets.outputJs('vendor-js') }}

In my mind this elements are most important.



14.4k

My enviroment should be alright. I am using these lines of code already and it's working:

$this->assets
    ->addJs('/assets/jquery/dist/jquery.min.js')
    ->addJs('/assets/bootstrap/js/bootstrap.min.js')
    ->addJs('/common/js/luna.js')
    ->addJs('/user/js/custom.js')
    ->addJs('/assets/datatables/jquery.dataTables.min.js')
    ->addJs('/assets/datatables/dataTables.bootstrap.js')

My root path is /. Could you provide an example of your assets definition inside your controller?

No problem...

$this->assets->collection('vendor-js')->addJs('vendor/jquery/dist/jquery.min.js');