subhamX / notion-easy-export

📘 Notion easy export converts your notion documents & databases into an ebook.
https://www.npmjs.com/package/notion-easy-export
Apache License 2.0
63 stars 4 forks source link

TypeError reading 'split' in buildMergedDoc #8

Closed louisfb01 closed 9 months ago

louisfb01 commented 9 months ago

I am running into this error when executing the basic javascript code from buildMergedDoc.

error: main: TypeError: Cannot read properties of undefined (reading 'split')

Is there a quick fix for this error? Is it because of a recent Notion update?

(base) Louiss-MacBook-Pro-2:notion-tests louis$ node test-convert.mjs
info: wkhtmltopdf is installed and in PATH. 🥳🥳
info: Starting current session...
info: Removing all files in session Files Dir!!!
info: Creating directories in session Files Dir!!!
info: Starting Html Export Subroutine
info: spaceId: 39cad34d-0e97-41a0-b21c-ec839f04bae0
error: main: TypeError: Cannot read properties of undefined (reading 'split')
levihanlen commented 9 months ago

I was just going to post an error about this because I got it too.

subhamX commented 9 months ago

Thank you folks for reporting the issue. Let me check it after work.

subhamX commented 9 months ago

Interestingly everything seems to be working fine for me:

image
louisfb01 commented 9 months ago

Could it be because I am a guest in the notion (with edits right) @subhamX ?

subhamX commented 9 months ago

My guess is that there is something wrong with getFileToken method.

Could you share the output for the following curl command:

curl -X POST "https://www.notion.so/api/v3/getAIUsageEligibility" \
     -H "Content-Type: application/json" \
     -H "Cookie: token_v2=<your_token_v2>" \
     -d '{"spaceId": "39cad34d-0e97-41a0-b21c-ec839f04bae0"}'

Give me the output after removing sensitive details. For example, mine is:

HTTP/2 200 
date: Mon, 29 Jan 2024 14:50:35 GMT
content-type: application/json; charset=utf-8
content-length: 103
set-cookie: AWSALBTG=xxx; Expires=Mon, 05 Feb 2024 14:50:35 GMT; Path=/
x-notion-request-id: xxx
content-security-policy: default-src 'none'
x-dns-prefetch-control: off
x-frame-options: SAMEORIGIN
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-download-options: noopen
x-content-type-options: nosniff
x-permitted-cross-domain-policies: none
referrer-policy: strict-origin-when-cross-origin
x-xss-protection: 0
etag: W/"67-xxx"
vary: Accept-Encoding
cf-cache-status: DYNAMIC
set-cookie: AWSALBTGCORS=/xxx; Expires=Mon, 05 Feb 2024 14:50:35 GMT; Path=/; SameSite=None; Secure
set-cookie: notion_browser_id=xxx; Domain=www.notion.so; Path=/; Expires=Tue, 28 Jan 2025 14:50:35 GMT; Secure
set-cookie: device_id=xxx; Domain=www.notion.so; Path=/; Expires=Tue, 28 Jan 2025 14:50:35 GMT; Secure
set-cookie: notion_check_cookie_consent=true; Domain=www.notion.so; Path=/; Expires=Tue, 30 Jan 2024 14:50:35 GMT; Secure
set-cookie: file_token=xxx; Domain=.notion.so; Path=/f; Expires=Tue, 28 Jan 2025 14:50:35 GMT; HttpOnly; Secure
set-cookie: token_v2=xxx; Domain=www.notion.so; Path=/; Expires=Tue, 28 Jan 2025 14:50:35 GMT; HttpOnly; Secure
set-cookie: notion_user_id=xxx; Domain=www.notion.so; Path=/; Expires=Tue, 28 Jan 2025 14:50:35 GMT; Secure
set-cookie: notion_users=xxx; Domain=www.notion.so; Path=/; Expires=Tue, 28 Jan 2025 14:50:35 GMT; Secure
set-cookie: __cf_bm=.xxx; path=/; expires=Mon, 29-Jan-24 15:20:35 GMT; domain=.notion.so; HttpOnly; Secure; SameSite=None
set-cookie: _cfuvid=xxx; path=/; domain=.notion.so; HttpOnly; Secure; SameSite=None
server: cloudflare
cf-ray: xxx
alt-svc: h3=":443"; ma=86400

{"isEligible":true,"type":"spaceAllowance","spaceUsage":0,"spaceLimit":20,"userUsage":0,"userLimit":20}%   
subhamX commented 9 months ago

Could it be because I am a guest in the notion (with edits right) @subhamX ?

Maybe. Could you confirm if you see an Export button in notion.so website?

image
louisfb01 commented 9 months ago

I can see this export button @subhamX !

I am also executing the code on my mac. I don't have the notion app installed. Not sure if either of those have impact.

subhamX commented 9 months ago

I am also executing the code on my mac. I don't have the notion app installed. Not sure if either of those have impact.

No it shouldn't affect that.

Could you please help me with the output of the curl cmd mentioned above. https://github.com/subhamX/notion-easy-export/issues/8#issuecomment-1914871324

louisfb01 commented 9 months ago

Oh, sorry about this; I didn't see the first message. This is what I get: I also cannot access the link you provided. I will try with my own notion pages tomorrow and update here assuming access is the issue for this error below.

"name":"ValidationError","debugMessage":"User cannot access space.","message":"Something went wrong. (400)"}
subhamX commented 9 months ago

@louisfb01;

I've applied a patch (not released yet). Could you please verify if it fixes the issue, by running the following set of commands.

git clone https://github.com/subhamX/notion-easy-export
cd notion-easy-export/
git checkout hotfix-8

npm install
NTEB_token_v2="change-me" NTEB_pageId="change-me" npm run build && npm run test
louisfb01 commented 9 months ago

Thank you for helping @subhamX ! Unfortunately, I get the same error with various page ID's and my token_v2.

> notion-easy-export@1.0.1 build
> tsc -b

> notion-easy-export@1.0.1 test
> node lib/tests/index.js

error: Invalid token_v2 or pageId
subhamX commented 9 months ago

Ah. my bad. I think the env variables are not getting applied correctly. Use the following instead:

git clone https://github.com/subhamX/notion-easy-export
cd notion-easy-export/
git checkout hotfix-8

npm install
npm run build 
NTEB_token_v2="change-me" NTEB_pageId="change-me" npm run test

error: Invalid token_v2 or pageId

this error message just mean that NTEB_token_v2 or NTEB_pageId env variable is empty. (There is still hope.. 🤞)

louisfb01 commented 9 months ago

Seems to be working! :)

Would you happen to know if there is a limit in number of pages or length of pages? It does work for a single page, but for one page where I have a dozen other pages with long text in there, I get a lot of "info: Current Task status: in_progress". And nothing appears in the input, output and tmp folders whereas it does work for a single page (for example it works for one page within this more global page).

Testing standalone doc generation
info: wkhtmltopdf is installed and in PATH. 🥳🥳
info: Starting current session...
info: Removing all files in session Files Dir!!!
info: Creating directories in session Files Dir!!!
info: Starting Html Export Subroutine
info: spaceId: 39cad34d-0e97-41a0-b21c-ec839f04bae0
info: Task Id: aeebfcc7-9e69-43b6-8406-80234e437733
info: Current Task status: in_progress
info: Current Task status: in_progress
info: Current Task status: in_progress
info: Current Task status: in_progress
info: Current Task status: in_progress
info: Current Task status: in_progress
...

Update: It partially worked. Is it because the content is too large?

info: Got the S3 download URL
info: Starting file download
info: File download successful
info: Removing all non dot files and folders from /Users/louis/Documents/GitHub/notion-easy-export/session_files/input
info: Files removal success
info: Starting file extraction
info: File extracted successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/louis/Documents/GitHub/notion-easy-export/session_files/output/standalone/Chapters to edit a75e0d3122574d79aa7100367e9c9ee6/1 LLMs Intro Chapter - What are LLMs e72856a619154b7d878fe03e6b5abcae.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                        
info: Ebook Saved Successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/louis/Documents/GitHub/notion-easy-export/session_files/output/standalone/Chapters to edit a75e0d3122574d79aa7100367e9c9ee6/10 Deployment 30f980e4012b49ef8552c394aacb24ec.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                        
info: Ebook Saved Successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/louis/Documents/GitHub/notion-easy-export/session_files/output/standalone/Chapters to edit a75e0d3122574d79aa7100367e9c9ee6/2 LLM Landscape a9df2699e3c349588ba4862a72f3c029.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                      
info: Ebook Saved Successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/louis/Documents/GitHub/notion-easy-export/session_files/output/standalone/Chapters to edit a75e0d3122574d79aa7100367e9c9ee6/3 LLMs in Practice 0654a49f59974ccb9b786eb02d14febe.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                        
info: Ebook Saved Successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/louis/Documents/GitHub/notion-easy-export/session_files/output/standalone/Chapters to edit a75e0d3122574d79aa7100367e9c9ee6/4 Langchain Intro 5da00107ef634b27a5637bbe95db6af8.pdf]
Loading pages (1/6)
Error: Failed to load https://notes.aimodels.fyi/content/images/size/w256h256/2023/03/Screen-Shot-2023-03-12-at-12.41.18-PM-1.png, with network status code 203 and http status code 404 - Error downloading https://notes.aimodels.fyi/content/images/size/w256h256/2023/03/Screen-Shot-2023-03-12-at-12.41.18-PM-1.png - server replied: Not Found
Warning: Failed to load https://notes.aimodels.fyi/content/images/2023/04/0_BKOvjpzn6SPKs81L.png (ignore)
Error: Failed to load https://notes.aimodels.fyi/content/images/size/w256h256/2023/03/Screen-Shot-2023-03-12-at-12.41.18-PM-1.png, with network status code 203 and http status code 404 - Error downloading https://notes.aimodels.fyi/content/images/size/w256h256/2023/03/Screen-Shot-2023-03-12-at-12.41.18-PM-1.png - server replied: Not Found
Warning: Failed to load https://notes.aimodels.fyi/content/images/2023/04/0_BKOvjpzn6SPKs81L.png (ignore)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                        
Exit with code 1 due to network error: ContentNotFoundError
node:internal/errors:865
  const err = new Error(message);
              ^

Error: Command failed: wkhtmltopdf --enable-local-file-access --margin-bottom 10 --margin-top 15 --header-spacing 5 --header-html /Users/louis/Documents/GitHub/notion-easy-export/assets/header/index.html toc --xsl-style-sheet /Users/louis/Documents/GitHub/notion-easy-export/assets/toc/styles.xls /Users/louis/Documents/GitHub/notion-easy-export/session_files/tmp/tmp.html /Users/louis/Documents/GitHub/notion-easy-export/session_files/output/standalone/Chapters to edit a75e0d3122574d79aa7100367e9c9ee6/4 Langchain Intro 5da00107ef634b27a5637bbe95db6af8.pdf
Loading pages (1/6)
Error: Failed to load https://notes.aimodels.fyi/content/images/size/w256h256/2023/03/Screen-Shot-2023-03-12-at-12.41.18-PM-1.png, with network status code 203 and http status code 404 - Error downloading https://notes.aimodels.fyi/content/images/size/w256h256/2023/03/Screen-Shot-2023-03-12-at-12.41.18-PM-1.png - server replied: Not Found
Warning: Failed to load https://notes.aimodels.fyi/content/images/2023/04/0_BKOvjpzn6SPKs81L.png (ignore)
Error: Failed to load https://notes.aimodels.fyi/content/images/size/w256h256/2023/03/Screen-Shot-2023-03-12-at-12.41.18-PM-1.png, with network status code 203 and http status code 404 - Error downloading https://notes.aimodels.fyi/content/images/size/w256h256/2023/03/Screen-Shot-2023-03-12-at-12.41.18-PM-1.png - server replied: Not Found
Warning: Failed to load https://notes.aimodels.fyi/content/images/2023/04/0_BKOvjpzn6SPKs81L.png (ignore)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                        
Exit with code 1 due to network error: ContentNotFoundError

    at checkExecSyncError (node:child_process:885:11)
    at execFileSync (node:child_process:921:15)
    at exportToEBook (/Users/louis/Documents/GitHub/notion-easy-export/lib/utils/convert_html_to_ebook.js:44:38)
    at traverseBuildAndExportStandalone (/Users/louis/Documents/GitHub/notion-easy-export/lib/build_docs/build_standalone_docs.js:48:59)
    at traverseBuildAndExportStandalone (/Users/louis/Documents/GitHub/notion-easy-export/lib/build_docs/build_standalone_docs.js:29:13)
    at buildStandaloneDocs (/Users/louis/Documents/GitHub/notion-easy-export/lib/build_docs/build_standalone_docs.js:17:5)
    at async /Users/louis/Documents/GitHub/notion-easy-export/lib/tests/index.js:16:9 {
  status: 1,
  signal: null,
  output: [
    null,
    Buffer(0) [Uint8Array] [],
    Buffer(6355) [Uint8Array] [
       76, 111, 97, 100, 105, 110, 103, 32, 112, 97, 103, 101,
      115,  32, 40,  49,  47,  54,  41, 10,  91, 62,  32,  32,
       32,  32, 32,  32,  32,  32,  32, 32,  32, 32,  32,  32,
       32,  32, 32,  32,  32,  32,  32, 32,  32, 32,  32,  32,
       32,  32, 32,  32,  32,  32,  32, 32,  32, 32,  32,  32,
       32,  32, 32,  32,  32,  32,  32, 32,  32, 32,  32,  32,
       32,  32, 32,  32,  32,  32,  32, 32,  32, 93,  32,  48,
       37,  13, 91,  61,  61,  61,  61, 61,  61, 62,  32,  32,
       32,  32, 32,  32,
      ... 6255 more items
    ]
  ],
  pid: 67152,
  stdout: Buffer(0) [Uint8Array] [],
  stderr: Buffer(6355) [Uint8Array] [
     76, 111, 97, 100, 105, 110, 103, 32, 112, 97, 103, 101,
    115,  32, 40,  49,  47,  54,  41, 10,  91, 62,  32,  32,
     32,  32, 32,  32,  32,  32,  32, 32,  32, 32,  32,  32,
     32,  32, 32,  32,  32,  32,  32, 32,  32, 32,  32,  32,
     32,  32, 32,  32,  32,  32,  32, 32,  32, 32,  32,  32,
     32,  32, 32,  32,  32,  32,  32, 32,  32, 32,  32,  32,
     32,  32, 32,  32,  32,  32,  32, 32,  32, 93,  32,  48,
     37,  13, 91,  61,  61,  61,  61, 61,  61, 62,  32,  32,
     32,  32, 32,  32,
    ... 6255 more items
  ]
}

Node.js v20.3.1
subhamX commented 9 months ago

Give me some info on the structure of the document you're trying to export. Like:

Or maybe clone the doc, remove sensitive info, and share a link? (If that's possible)

I really appreciate your time, brother. :)

louisfb01 commented 9 months ago

For sure! And likewise, thanks for your help and time! :)

So the main page just has the other pages. 10 of them. so just: page 1 linking to page 2,3,4,5,6,7,8,9,10... (no other pages in those)

The other pages are quite long, though, around that with some images: 33k, 15k, 10k, 7k, 15k, 5k, 3k, 5k, 13k, 39k, 16k

I can't really share the information in there unfortunately...

subhamX commented 9 months ago

I think the issue is either:

  1. with downloading this big zip file from notion
  2. with the pdf creation tool

I'll merge the part to fix the permission issue. And will try to replicate the error.

louisfb01 commented 9 months ago

Thanks for looking into it! :)