JMSTwigJsBundle icon indicating copy to clipboard operation
JMSTwigJsBundle copied to clipboard

"goog is not defined" in production

Open ajbdev opened this issue 12 years ago • 6 comments

Howdy,

I've been using this package to develop a couple templates that are only loaded via javascript. Everything works great in development. Templates are loaded as follows:

In my base.twig.html....

{% javascripts
    "@MyAppBundle/Resources/views/Profile/modal.profile.html.twig"
    "@MyAppBundle/Resources/views/Signup/modal.signup.html.twig"
       filter="twig_js,yui_js" %}
<script language="javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

However, when I go to production I dump out the assets and and attempt to load the page, I get:

Uncaught ReferenceError: goog is not defined 

It seems like the templates aren't getting compiled correctly for production. My understanding is that Google's closure library should be compiled (with only the required features) into the template itself. This seems work during development, but is not happening when I dump the assets to the filesystem for production usage.

Any thoughts on what I could be doing wrong here?

ajbdev avatar Sep 16 '12 05:09 ajbdev

Did you include twig.js's runtime code (twig.js or twig.dev.js)?

schmittjoh avatar Sep 16 '12 17:09 schmittjoh

Hmm. I think this may somehow be related to the fact that I symlinked twig.js into my AppBundle's Resources\public\js directory. I was pulling in twig.js like this:

{% javascripts
    '@MyAppBundle/Resources/public/js/*'
    filter='?yui_js'
    %}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

However, for some reason it doesn't compile in twig.js if I am using a symlink and I use a wildcard (*) to pull in JS files. I fixed this by explicitly listing each javascript file to load instead of using the wildcard. This seems to be an issue with assetic (maybe... this seems like reasonable behavior anyways) and not JMSTwigJsBundle.

Thanks for pointing me in the right direction.

On a side note, is this the "appropriate" way to include Twig.js? I couldn't figure out how to load in the resource from the source bundle so I just symlinked it.

ajbdev avatar Sep 16 '12 18:09 ajbdev

@ajbdev See the closed How should twig.js be included? issue.

{% javascripts
     '%kernel.root_dir%/../vendor/jms/twig-js/twig.js'
...

adam-lynch avatar Oct 10 '12 07:10 adam-lynch

Just had the same problem: "goog is not defined" .

Fixed by using the good twig.js file. (i was using the src-js/twig.js file)

Nek- avatar Nov 05 '12 00:11 Nek-

Just had the same problem too: In my composer.json file I had only: "jms/twig-js-bundle" : "dev-master" And I had the twig.js file using bower

To fix, I just added in composer.json: "jms/twig-js" : "dev-master" , removed the twig.js line in bower.json and change to '%kernel.root_dir%/../vendor/jms/twig-js/twig.js' in my layout as specified above

works perfect, thanks (ps: and thanks for the bundle)

nouchka avatar Feb 02 '15 22:02 nouchka

Same problem : "goog is not defined"

  • composer.json : "jms/twig-js-bundle": "dev-master"

  • layout.html.twig : {% javascripts '%kernel.root_dir%/../vendor/jms/twig-js/twig.js' '@AppBundle/Resources/views/Model/_item.twig' output='js/templates.js' filter="twig_js" %}

    {% endjavascripts %}

and i can see in my templates.js : ... goog.require('twig'); goog.require('twig.filter'); ...

PaskR avatar May 14 '15 09:05 PaskR