jimmywarting / native-file-system-adapter

File system, based on the spec reference implementation
https://jimmywarting.github.io/native-file-system-adapter/example/test.html
MIT License
484 stars 43 forks source link

ParseError: 'import' and 'export' may appear only with 'sourceType: module' when trying to #28

Open cosmikwolf opened 2 years ago

cosmikwolf commented 2 years ago

when I put the following in my code:

import { getOriginPrivateDirectory } from 'native-file-system-adapter'

I get the following error in the browser console:

node_modules/native-file-system-adapter/src/es6.js:1
import showDirectoryPicker from './showDirectoryPicker.js'
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
bundleError @ 07_meltimush_webcodecs_fileapi:4
(anonymous) @ 07_meltimush_webcodecs_fileapi:231

Any idea what other information I can gather to figure out what is going on? My searches have pointed me towards browserify or gulp, but I am not sure what changes to try.

olee commented 2 years ago

This is actually a more general issue of this library being not having a properly built version at all. While there exists a rollup config etc. the npm package does not have any dist directory.

@jimmywarting would you mind publishing a new package which contains a built version of the library?

jimmywarting commented 2 years ago

it have kind of bit me as well with regards to extending the streams. Sometimes I wished that the bundle wouldn't include the stream polyfill at all but it's get included for whatever reason when i use my own bundler or any cdn.

I'm thinking of removing the hole stream polyfill dependency alltogheter and demand that the users use it in a environment that has the support for it

jcbhmr commented 1 year ago

I'm thinking of removing the hole stream polyfill dependency alltogheter and demand that the users use it in a environment that has the support for it

Considering the 95% browser support, I think this is a good idea. https://caniuse.com/streams image Related: https://caniuse.com/mdn-api_readablestream https://caniuse.com/mdn-api_writablestream https://caniuse.com/mdn-api_transformstream

Remember, you can always provide an example! Like:

import "streams-polyfill-from-somewhere"
import "your-polyfill-that-needs-TransformStream-or-something"

I also think that including browser support matrices from something like https://caniuse.bitsofco.de/ is a big plus! 😊