GoogleChromeLabs / browser-fs-access

File System Access API with legacy fallback in the browser
https://googlechromelabs.github.io/browser-fs-access/demo/
Apache License 2.0
1.38k stars 84 forks source link

Index.js makes some build tools think that it is a CommonJS module instead of ESM #55

Closed AsyncBanana closed 3 years ago

AsyncBanana commented 3 years ago

The index.js seems to be a CommonJS module to some build tools (notably Sveltekit's static adapter) because it does not have a .mjs suffix and there is no "type": "module" in the package.json. Two solutions are to add the module type to package.json, which would allow for the removal of all .mjs suffixes, or add an mjs suffix to index.js.

Amatewasu commented 3 years ago

+1, it looks like it prevents me from doing some tests with Jest.

tomayac commented 3 years ago

Just released v0.18.1 that should fix this.

Amatewasu commented 3 years ago

Thanks a lot for your great reactivity! I upgraded the package to 0.18.1 (and checked the associated package.json file in my _nodemodules folder, the module type is here) but I still have the error when running tests with Jest (but it's running fine otherwise). I am not sure it comes from browser-fs-access.

But here's my trace if it can help in any way:

XXXXXanonymizationXXXXX\node_modules\browser-fs-access\dist\index.js:2
    export{fileOpen}from"./file-open.mjs";export{directoryOpen}from"./directory-open.mjs";export{fileSave}from"./file-save.mjs";export{default as supported}from"./supported.mjs";
    ^^^^^^

    SyntaxError: Unexpected token 'export'

      1 | import { polygon, Properties } from '@turf/helpers';
      2 | import { union } from '@turf/turf';
    > 3 | import { directoryOpen, FileWithDirectoryHandle, supported as fsSupported } from 'browser-fs-access';
        | ^

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
tomayac commented 3 years ago

In #42, this was traced down to https://github.com/facebook/jest/issues/2550#issuecomment-810144368.