wasm-pandoc
wasm-pandoc copied to clipboard
JavaScript heap out of memory
problem:
I try to convert docx to html and get errors from terminal, eg. 'JavaScript heap out of memory'.
btw, I convert T.Text to T.Text, like markdown to html, is successful,and I convert BSL.ByteString to T.Text is block by (reader def input)
devices and os:
- MacOS: 12.2.1 (21D62)
- docker: mac docker app v4.5.0 (74594)
- nodejs: 16.13.1
- browser: mac chrome v96.0.4664.110
code and detail:
example code: https://github.com/pasicopan/wasm-pandoc detail:
// modify Main.hs
convertFromTo :: T.Text -> String -> BSL.ByteString -> Maybe T.Text
convertFromTo from to input =
case runPure $ (getReader from) of
Left err -> error (show err)
Right (ByteStringReader reader, es) -> case runPure $ reader def input of
Left err -> error (show err)
Right doc -> case runPure $ (writerOf to) def doc of
Left err -> error (show err)
Right output -> Just output
convert :: JSString -> JSString -> JSUint8Array -> JSString
convert from to =
textToJSString
. fromMaybe (T.pack "")
. convertFromTo (textFromJSString from) (fromJSString to)
. BSL.fromStrict
. byteStringFromJSUint8Array
foreign export javascript "convert" convert :: JSString -> JSString -> JSUint8Array -> JSString
error from browser
index.js:1 PandocParseError "No entry on path: META-INF/container.xml"
CallStack (from HasCallStack):
error, called at app/Main.hs:36:26 in main:Main
f @ index.js:1
await in f (async)
(anonymous) @ VM4305:1
index.js:1 Uncaught RangeError: Offset is outside the bounds of the DataView
at DataView.getBigUint64 (<anonymous>)
at st.i64Load (index.js:1)
at yt.evacuateClosure (index.js:1)
at yt.scavengeStackChunk (index.js:1)
at yt.scavengeClosure (index.js:1)
at yt.scavengeLoop (index.js:1)
at yt.performGC (index.js:1)
at ht.returnedFromTSO (index.js:1)
at ht.tick (index.js:1)
at index.js:1
error from nodejs 16
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x10837c815 node::Abort() (.cold.1) [/Users/xxx/.nvm/versions/node/v16.13.1/bin/node]
2: 0x10707baa9 node::Abort() [/Users/xxx/.nvm/versions/node/v16.13.1/bin/node]
3: 0x10707bc1f node::OnFatalError(char const*, char const*) [/Users/xxx/.nvm/versions/node/v16.13.1/bin/node]