mjmlio / mjml2json

A package to convert a MJML template from XML syntax to JSON
22 stars 17 forks source link

When using example from README got: TypeError: mjml2json is not a function #5

Closed neminovno closed 5 years ago

neminovno commented 5 years ago

const output = mjml2json(input) ^

TypeError: mjml2json is not a function at Object. (C:\dev\nodejs-projects\mjml2json-test\index.js:17:16) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Function.Module.runMain (internal/modules/cjs/loader.js:742:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

How to solve this?

neminovno commented 5 years ago

Solved with creating new file myfile.d.ts:

interface MJMLParsingOpts {
    fonts?: { [key: string]: string; };
    keepComments?: boolean;
    beautify?: boolean;
    minify?: boolean;
    validationLevel?: 'strict' | 'soft' | 'skip';
    filePath?: string;
}

declare module "mjml2json" {
    function mjml2json(inp: string, opts?: MJMLParsingOpts): {};
    export default mjml2json;
}

and use it like this:

const mjml2json = require('mjml2json').default;
(...)
const output = mjml2json(input);