Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"goog is not defined" in production #17

Open
ajbdev opened this issue Sep 16, 2012 · 6 comments
Open

"goog is not defined" in production #17

ajbdev opened this issue Sep 16, 2012 · 6 comments

Comments

@ajbdev
Copy link

ajbdev commented Sep 16, 2012

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?

@schmittjoh
Copy link
Owner

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

@ajbdev
Copy link
Author

ajbdev commented Sep 16, 2012

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.

@adam-lynch
Copy link

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

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

@Nek-
Copy link

Nek- commented Nov 5, 2012

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)

@nouchka
Copy link

nouchka commented Feb 2, 2015

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)

@PaskR
Copy link

PaskR commented May 14, 2015

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" %}

    <script src="{{ asset_url }}"></script>

    {% endjavascripts %}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants