jsartoolkit5 icon indicating copy to clipboard operation
jsartoolkit5 copied to clipboard

Error: "FS is not defined"

Open sorskoot opened this issue 7 years ago • 8 comments

This is the actual error shown in the console: artoolkit.api.js:1670 Uncaught ReferenceError: FS is not defined at writeByteArrayToFS (artoolkit.api.js:1670) at XMLHttpRequest.oReq.onload (artoolkit.api.js:1689)

It points to this function in artoolkit.api.js: function writeByteArrayToFS(target, byteArray, callback) { FS.writeFile(target, byteArray, { encoding: 'binary' }); // console.log('FS written', target); callback(byteArray); } Is there any way to get this fixed? For now I added FS.writeFile as an empty function to the global scope to get rid of the error.

sorskoot avatar May 11 '18 21:05 sorskoot

@sorskoot: Same here please list the steps that you are taking until this error occurs, thanks.

ThorstenBux avatar May 14 '18 14:05 ThorstenBux

I had the same issue, it is happening after reloading a page several times on Android/Chrome. My guess is that Chrome does not free all the memory used when reloading a page.

pikilipita avatar May 21 '18 14:05 pikilipita

someone could look at this? same error https://github.com/artoolkitx/jsartoolkit5/issues/83

nicolocarpignoli avatar Jun 21 '19 07:06 nicolocarpignoli

As posted on my branch-PR probably this is a "emscripten" issue the problem is described here: https://github.com/emscripten-core/emscripten/issues/854 and https://stackoverflow.com/questions/15056752/emscripten-using-filesystem-fs

kalwalt avatar Jun 25 '19 11:06 kalwalt

So maybe the fact that the flow did not 'arrive' till a FS function call, meant that FS was not imported at all. Great, thanks!

nicolocarpignoli avatar Jun 25 '19 12:06 nicolocarpignoli

So maybe the fact that the flow did not 'arrive' till a FS function call, meant that FS was not imported at all. Great, thanks!

@nicolocarpignoli yes, but the fact remains that the code works for me but not for you, This puzzling me a lot...

kalwalt avatar Jun 25 '19 13:06 kalwalt

I'm running into the same issue with my own build now.

From what I found this is not related to Node.js or but actually a reference to Emscripten's own FS module as described here.

Their API seems to have changed now. Reading the documentation I'd expect an FS object to be available on the generated module but I can only see methods like FS_createFolder or FS_createDataFile. Also this API must be enabled by building the module with -s FORCE_FILESYSTEM=1

In case anyone has already solved this, how did you do it?

andypotato avatar Feb 19 '20 06:02 andypotato

Solved ... you need to add this to your emscripten module build configuration:

FLAGS += ' -s "EXTRA_EXPORTED_RUNTIME_METHODS=[\'FS\']"';

Afterwards FS will be available as member on the exported module and you can reference it via artoolkit.FS - You simply need to replace FS. with artoolkit.FS. and it should work.

andypotato avatar Feb 19 '20 07:02 andypotato