twitter / hogan.js

A compiler for the Mustache templating language
http://twitter.github.io/hogan.js
Apache License 2.0
5.14k stars 431 forks source link

Cannot resolve module 'hogan' in ... #257

Closed labike closed 5 years ago

labike commented 7 years ago

package.json

"devDependencies": {
    "css-loader": "^0.28.4",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.11.2",
    "html-loader": "^0.4.5",
    "html-webpack-plugin": "^2.29.0",
    "style-loader": "^0.18.2",
    "url-loader": "^0.5.9",
    "webpack": "^1.15.0",
    "webpack-dev-server": "^1.16.5"
  },
  "dependencies": {
    "hogan": "^1.0.2"
  }

ma.js

'use strict';
var Hogan = require('hogan');
var conf = {
    serverHost: ''
};
//渲染html模板
    renderHtml: function(htmlTemplate, data){
        var template = Hogan.compile(htmlTemplate),
            result = template.render(data);
        return result;
    },

index.js

'use strict';

var _ma = require('util/ma.js');

var html = '<div>{{data}}</div>';
var data = {
    data: 123
}
console.log(_ma.renderHtml(html, data));

ERROR in ./src/util/ma.js Module not found: Error: Cannot resolve module 'hogan' in /Users/Macx/Documents/mall/mall-fe/src/util @ ./src/util/ma.js 9:12-28

zhangbinzhbb commented 6 years ago

已经决。 hogan新版本的引入方式: var Hagon = require('hagon.js');

具体参见官方文档

Haroenv commented 6 years ago

This should actually be:

var Hogan = require('hogan.js');

and hogan.js in package.json