markdown-confluence / markdown-confluence

Publish your Markdown Files to Confluence

Home Page:https://markdown-confluence.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I use it in Common JS file as it is ESModule.

Indronil opened this issue · comments

I want to use it with require.

Trying this
const fs = require('fs');
const path = require('path');
const markdownConfluence = require('@markdown-confluence/lib');

const mdFilePath = '../RELEASE-NOTES.md'; // Path to your Markdown file
const absoluteMdFilePath = path.resolve(__dirname, mdFilePath); // Original MD File

async function readMarkdownFile() {
try {
const content = await fs.readFile(absoluteMdFilePath, { encoding: 'utf8' });
console.log("MD Content::::", content);
const confluenceContent = markdownConfluence.convertMDtoADF(content);
console.log("Confluence Content::::", confluenceContent);
} catch (error) {
console.error("Error reading or converting the Markdown file:", error);
}
}

readMarkdownFile();

Error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/ghoshi/Desktop/Work/vcap-platform-applications/node_modules/@markdown-confluence/lib/dist/index.js
require() of ES modules is not supported.
require() of /Users/ghoshi/Desktop/Work/vcap-platform-applications/node_modules/@markdown-confluence/lib/dist/index.js from /Users/ghoshi/Desktop/Work/vcap-platform-applications/test.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/ghoshi/Desktop/Work/vcap-platform-applications/node_modules/@markdown-confluence/lib/package.json.