javascript - require('...') module not found!!
PHP中文网
PHP中文网 2017-06-26 10:50:33
0
3
858

Directory Structure

The following is the content of hogan.html

var Hogan = require('hogan.js'); mytools = { renderHtml: function(htmlTemplate, data) { var template = Hogan.compile(htmlTemplate); var result = template.render(data); return result; } } var htmlTpl = '

{{name}}

'; var data = '张三'; mytools.renderHtml(htmlTpl ,data);

I am npm i --save hogan.js to install the js module.
require('hogan.js') in html
will report an error require is not defined.

Usually used directly in webpack.
How to use require??

PHP中文网
PHP中文网

认证0级讲师

reply all (3)
迷茫

This means you don’t have this in yournode_modulesdirectory. Check where you installed it

I just didn’t see clearly that you wroterequireinhtml, which only supportsrequireinjs

So have you solved it? Do you want torequireinsidejsorrequireinsidehtml?

If you want to import

jsnormallyrequireandhtml, just go to thenode_modulesfolder and find the path tohongan.js

    女神的闺蜜爱上我

    requireis a built-in method ofnode.js. When you run Webpack,npm run buildactually uses node to run the webpack compilation script, so require is supported. But now that you have written it natively, you are out of touch withnode.js, which does not natively supportrequire()loading packages.

    The correct way is to add files directly using

      洪涛

      You should write the absolute path to Hogan .js

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!