Adding jadeify to a node -express-browsify project

Context

I cloned a basic node -browserify template project and raised it. I am using a coffee script. Right now I'm trying to add jadeify to the equation as follows:

bundle = browserify entry: __dirname + "/app/init.coffee" debug: true mount: "/app.js" bundle.use jadeify __dirname + '/views' app.use bundle 

This is before I even try to use jadeify anywhere.

Question

Everything works until I add bundle.use(jadeify(__dirname + '/views')) as browser middleware. Then I get the following error message in the browser console:

 Uncaught ReferenceError: __require is not defined 

According to the browser console, the source of this message is /app.js .

Question

Why does this script fail as soon as I try to add jadeify middleware for the browser?

Motivation

I thought it would be more convenient to reuse server-side jade patterns on the client side, so I am debugging underline patterns in favor of jade. While doing my research, I came across this solution to a related question , which suggests using jadeify. It seems doable, but something seems unsuccessful.

+4
source share
2 answers

Can get around jadeify with browjadify

 Usage: browjadify --entry=app.coffee >bundle.js 

Source: browjadify

 #!/usr/bin/env node var jade = require('jade') var browserify = require('browserify') var fs = require('fs'); var argv = require("optimist").argv; var b = browserify() b.register('.jade', function(body) { var options = {"client": true, "compileDebug": false}; body = "module.exports = " + jade.compile(body, options).toString() +";"; return body; }); var jaderuntime = require('fs').readFileSync(__dirname+"/node_modules/jade/runtime.js", 'utf8'); b.prepend(jaderuntime); // Brings in var jade that jade.compile needs b.addEntry(argv.entry); // gets browserify to do its thing console.log(b.bundle()); // the bundled output 
+4
source

I also saw this today and was able to fix it.

The problem for me was that jadeify depends on the browser version no more than 1.2.9, but the current version of the browser in the git repository is newer (much newer, something above 1.8, if I remember correctly). And, being new to working with this installation, I first installed a browser (with the latest version), and then jadeify installed my own dependent browser (with a supported version) in my own module space.

Then, when I launched my application, the browser that I called was the new version, but the libraries that jadeify used were the old version, and this created a conflict somewhere and therefore the error you also saw.

In the end, I just reinstalled the latest supported version of the browser in my application space and fixed it.

LATER EDIT:

The problem with the fix above was that browserify@1.2.9 had no caching and very slowly rebooted the server. But I managed to find a browserijade that works with the latest version of the browser (1.9.4) and performs the same actions as jadeify.

Hope this helps!

+2
source

Source: https://habr.com/ru/post/1398089/


All Articles