BrowserFS icon indicating copy to clipboard operation
BrowserFS copied to clipboard

path.join throw error in Service Worker

Open jcubic opened this issue 5 years ago • 16 comments

If you call this path.join('/'. 'file') in service worker it throw exception:

Error: ENOENT: No such file or directory., '/'
Error
    at new ApiError (https://cdn.jsdelivr.net/npm/[email protected]/dist/browserfs.js:5430:22)
    at Function.FileError (https://cdn.jsdelivr.net/npm/[email protected]/dist/browserfs.js:5455:16)
    at Function.ENOENT (https://cdn.jsdelivr.net/npm/[email protected]/dist/browserfs.js:5458:21)
    at https://cdn.jsdelivr.net/npm/[email protected]/dist/browserfs.js:13987:37
    at IDBRequest. (https://cdn.jsdelivr.net/npm/[email protected]/dist/browserfs.js:14270:17)

it work outside of worker.

jcubic avatar May 03 '20 11:05 jcubic

@jcubic Please try with the latest commit. If it still does not work, a PR would be greatly appreciated!

james-pre avatar Mar 09 '23 23:03 james-pre

Will check, is the latest version published to NPM?

jcubic avatar Mar 10 '23 10:03 jcubic

@jcubic I don't believe so. You will need to clone the repo and build from source.

james-pre avatar Mar 10 '23 12:03 james-pre

ok, will see if I will be able to test tomorrow. I'm on a trip but got a laptop with me.

jcubic avatar Mar 10 '23 13:03 jcubic

I'm not able to build the project got error from NodeJS:

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (/home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/util/createHash.js:90:53)
    at NormalModule._initBuildHash (/home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/NormalModule.js:386:16)
    at handleParseError (/home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/NormalModule.js:434:10)
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/NormalModule.js:466:5
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/NormalModule.js:327:12
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:370:3
    at iterateNormalLoaders (/home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:211:10)
    at iterateNormalLoaders (/home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:218:10)
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:233:3
    at context.callback (/home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at processMap (/home/kuba/projects/jcubic/BrowserFS/node_modules/source-map-loader/index.js:103:3)
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/source-map-loader/index.js:53:6
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

This seems to be a common NodeJS error but I'm not able to solve it by adding:

export NODE_TLS_REJECT_UNAUTHORIZED=0

jcubic avatar Mar 11 '23 18:03 jcubic

Interesting... I don't believe that error is related to BrowserFS so it is most likely with your machine.

james-pre avatar Mar 12 '23 01:03 james-pre

This is common error with Node and the library failed to handle it properly. sent from Android12.03.2023 2:20 AM "Dr. Vortex" @.***> napisał(a): Interesting... I don't believe that error is related to BrowserFS so it is most likely with your machine.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

jcubic avatar Mar 12 '23 11:03 jcubic

@jcubic Have you tried this Stack Overflow answer? It should prevent the SSL error.

james-pre avatar Mar 23 '23 18:03 james-pre

@james-pre thanks it works, I think that I've missed this. But I think that all those errors are problems with the library that doesn't support the latest NodeJS. I have the same with a project I'm maintaining and this is my project's fault that this throws an error and requires disabling security hacks to work.

jcubic avatar Mar 23 '23 20:03 jcubic

@jcubic I'm working on updating all of BrowserFS' various dependencies so it should get fixed soon.

james-pre avatar Mar 23 '23 20:03 james-pre

I've added browserFS build file to my project that uses service worker and I've got a different error:

Error: ENOENT: No such file or directory., '/'

from fs.stat('/test/index.html').

The whole code was working fine. This my setup:

self.addEventListener('fetch', function (event) {
    let path = BrowserFS.BFSRequire('path');
    let fs = new Promise(function(resolve, reject) {
        BrowserFS.configure({ fs: 'IndexedDB', options: {} }, function (err) {
            if (err) {
                reject(err);
            } else {
                resolve(BrowserFS.BFSRequire('fs'));
            }
        });
    });
    event.respondWith(fs.then(function(fs) {
        // ...
    });
});

I'm not sure if the API changed. If I changed the app to also use new BrowserFS that app stops working and throws an error on ls command on the root directory.

What are the breaking changes in 2.0?

jcubic avatar Mar 23 '23 20:03 jcubic

@jcubic

configureAsync (source code) should simplify the code your using. In addition, you no longer need to supply options for IndexedDB (see #352).

As for the error, I'm not entirely sure why it is being thrown. I would suggest you change the code to use configureAsync and change the event listener to use async/await and await the configureAsync call.

I will look into the error more in the mean time (and hopefully fix the ApiError stack)

james-pre avatar Mar 24 '23 18:03 james-pre

@jcubic I just fixed the issues causing the errors above in #355. You should be able to run BFS normally again.

Specifically, this commit fixed multiple errors (see the commit notes)

james-pre avatar Mar 29 '23 12:03 james-pre

Thanks, Will check my app with the latest version.

jcubic avatar Mar 29 '23 16:03 jcubic

The ls command works but when I want to clone the repo. Got an error from this function:

AsyncKeyValueFileSystem.prototype.getDirListing = function getDirListing (tx, p, inode, cb) {
  if (!inode.isDirectory()) {
	cb(ApiError.ENOTDIR(p));
  }
  else {
	tx.get(inode.id, function (e, data) {
	  if (noError(e, cb)) {
	    try {
	      cb(null, JSON.parse(data.toString()));
	    }
	    catch (e) {
	      // Occurs when data is undefined, or corresponds to something other
	      // than a directory listing. The latter should never occur unless
	      // the file system is corrupted.
	      cb(ApiError.ENOENT(p));
	    }
	  }
	});
  }
};

data is undefined.

Also, I needed to delete the old database because it was not compatible and was throwing errors.

jcubic avatar Mar 30 '23 14:03 jcubic

Closing (stale). If you would like to reopen this issue, please do so by creating a new issue in the relevant repositories of @browser-fs

james-pre avatar Oct 25 '23 00:10 james-pre