In a Node.js file:
This code executes perfectly fine:
import { Client } from '@notionhq/client' import { NotionCompatAPI } from 'notion-compat' (async() => { const token = 'your-token' const notion = new NotionCompatAPI( new Client({ auth: token }) ) const pageId = 'your-page-id' const recordMap = await notion.getPage(pageId) console.log(recordMap) })()
However, when I use Express as the Node.js backend framework, I encounter an error:
[ERROR] 14:41:09 Error: require() of ES Module path/node_modules/.pnpm/notion-compat@7.1.6_@notionhq+client@2.2.15/node_modules/notion-compat/build/index.js from path/src/notion/index.ts not supported. Instead change the require of index.js in path/src/notion/index.ts to a dynamic import() which is available in all CommonJS modules.
Specific code file: https://codesandbox.io/s/j67h8w
Key code:
import { Client } from '@notionhq/client' import { NotionCompatAPI } from 'notion-compat' export const getBlocks = async(blockId?: string) => { const token = 'your-token' const notion = new NotionCompatAPI( new Client({ auth: token }) ) const pageId = 'your-page-id' const recordMap = await notion.getPage(pageId) return recordMap }
Top comments (0)