nunjucks: require('nunjucks') within webpack returns an empty object

When requiring nunjucks within a webpack project, an empty object is returned instead of nunjucks.

eg.

// webpack.config.js
module.exports = {
    entry: './main.js'
};
// main.js
var nunjucks = require('nunjucks');
console.log(nunjucks); // outputs {}

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Comments: 31 (20 by maintainers)

Most upvoted comments

Gotcha. Removing chokidar seems like a solid idea!

Thanks for merging this for now, and also for your help maintain this awesome library. It is so slick in so many ways!

@carljm i think it should be documented, because it also seems to be doing the same thing with browserify. Anyone coming to nunjucks for the 1st time doesn’t expect this resolution as the default just my $0.02.

to do it within browserify you need to shim it like webpack using browserify-shim transform.

adding something like this to package.json:

  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  },
  "browserify-shim": {
    "nunjucks": "nunjucks"
  }

@jgerigmeyer Do you think that’s worth adding to the docs somewhere?