rotundasoftware / nunjucksify

Everything you expect from a module named nunjucksify and more.
34 stars 10 forks source link

Uncaught TypeError: nunjucks.Environment is not a function #16

Closed daslicht closed 8 years ago

daslicht commented 8 years ago

Hi, I I have the following setup:

test.js

var $ = require( 'jquery' )
var tmpl = require( './myWidget.nunj' );
var nunjucks = require('nunjucks');
console.log( tmpl.render( { menu : 'chorizo' } ) ); 

myWidget.nunj:

<div>{{ menu }}</div>

package.json:

  "browserify": {
    "transform": [
      [
        "nunjucksify"
      ]
    ]
  },
  "browser": {
    "nunjucks": "nunjucks/browser/nunjucks-slim"
  }

bundle include:

app.get('/bundle.js', browserify('./app/test.js'));
...
<script src="/bundle.js"></script>

I get the following error in the browser: Uncaught TypeError: nunjucks.Environment is not a function

What do I miss , please?

daslicht commented 8 years ago

According to the manual the Envigronment should be automatically created if not defined, no? :

https://github.com/rotundasoftware/nunjucksify#caring-for-the-environment

dgbeck commented 8 years ago

Hm, yes seems like that should work at first glance. Can you let us know what version of nunjucks you are using so we can reproduce?

In the mean time as a work around you could try giving nunjucks an evnironment

var $ = require( 'jquery' )
var nunjucks = require('nunjucks');
nunjucks.env = new nunjucks.Environment( null, { autoescape : false } );

var tmpl = require( './myWidget.nunj' );
console.log( tmpl.render( { menu : 'chorizo' } ) ); 
daslicht commented 8 years ago

"nunjucks": "^2.4.1",

aboutaaron commented 8 years ago

I also ran into this issue. Any advice would be helpful!

dgbeck commented 8 years ago

Hi @aboutaaron ,

Nunjucksify is in a funny state right now because of https://github.com/mozilla/nunjucks/issues/507 . That issue was resolved with the merge of https://github.com/mozilla/nunjucks/pull/753 , but we are still waiting for the next nunjucks release before we can update the dependency and resolve the funniness in nunjucksify.

In the mean time I recommend using the following in your package.json

{
   "dependencies": {
      "nunjucks": "git://github.com/dgbeck/nunjucks#68a456b3d80a0961f4fab8bc79c5c8a4e304246a",
      "nunjucksify": "git://github.com/rotundasoftware/nunjucksify#89b2dc5204560f819278320bca04751fbb24bbb9",
       ...
   }
}

When using those versions of nunjucks / nunjucksify, everything should work as expected.

Closing this issue for now. Let me know if you continue to have problems.

Thanks for stopping by!

daslicht commented 8 years ago

please keep us posted on this issue