souvikinator / notion-to-md

Convert notion pages, block and list of blocks to markdown (supports nesting and custom parsing)
https://www.npmjs.com/package/notion-to-md
MIT License
1.11k stars 91 forks source link

Problem with start (Object.fromEntries is not a function) #25

Closed BlackDiverX closed 2 years ago

BlackDiverX commented 2 years ago

Hello! My code is:

import * as fs from 'fs';
import * as path from 'path';
const { Client } = require("@notionhq/client");
//const { NotionToMarkdown } = require("notion-to-md");
// or
 import {NotionToMarkdown} from "notion-to-md";

const notion = new Client({
  auth: "secret_M*************Z",
});

// passing notion client to the option
const n2m = new NotionToMarkdown({ notionClient: notion });

(async () => {
  const mdblocks = await n2m.pageToMarkdown("ed937efd320c43a7bc32227728bcbc1e");
  const mdString = n2m.toMarkdownString(mdblocks);

  //writing to file
  fs.writeFile("test.md", mdString, (err) => {
    console.log(err);
  });
})();

then i start with command:

npx ts-node 1.ts

And get error:

npx: installed 15 in 2.176s
TypeError: Object.fromEntries is not a function
    at pick (/node_modules/@notionhq/client/src/helpers.ts:19:17)
    at Object.list (/node_modules/@notionhq/client/src/Client.ts:280:22)
    at getBlockChildren (/node_modules/notion-to-md/src/utils/notion.ts:15:60)
    at NotionToMarkdown.pageToMarkdown (/node_modules/notion-to-md/src/notion-to-md.ts:60:42)
    at /1.ts:16:30
    at Object.<anonymous> (/1.ts:23:3)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module.m._compile (/root/.npm/_npx/8486/lib/node_modules/ts-node/src/index.ts:1455:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/root/.npm/_npx/8486/lib/node_modules/ts-node/src/index.ts:1458:12)
null

Please help

souvikinator commented 2 years ago

Works for me.

May I know the @notionhq/client version you are using?

BlackDiverX commented 2 years ago

I'm use versions:

root@37bdd3dde543:/app# npm view typescript version
4.6.2
root@37bdd3dde543:/app# npm view ts-node version
10.7.0
root@37bdd3dde543:/app# npm view notion-to-md version
2.3.2
root@37bdd3dde543:/app# npm view @notionhq/client version
1.0.2
BlackDiverX commented 2 years ago

All ok after update nodejs to 17 version.

souvikinator commented 2 years ago

Alright then I'll close the issue. Feel free to reopen on further issues.