Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How do I access FileSystem in wasmJs? #1463

Open
stepango opened this issue Apr 1, 2024 · 3 comments
Open

Question: How do I access FileSystem in wasmJs? #1463

stepango opened this issue Apr 1, 2024 · 3 comments

Comments

@stepango
Copy link

stepango commented Apr 1, 2024

I'm using following multiplatform configuration for wasm target

wasmJs {
    binaries.executable()
    nodejs()
}

trying to add nodefilesystem dep

sourceSets {
    val wasmJsMain by getting {
        dependencies {
            implementation("com.squareup.okio:okio-nodefilesystem:3.9.0")
        }
    }
 }

But getting following error

Could not determine the dependencies of task ':kotlinNpmInstall'.
> Could not resolve all dependencies for configuration ':llama2:wasmJsNpmAggregated'.
  > Could not resolve com.squareup.okio:okio-nodefilesystem:3.9.0.
    Required by:
        project :llama2
     > No matching variant of com.squareup.okio:okio-nodefilesystem:3.9.0 was found. The consumer was configured to find a library for use during 'kotlin-runtime', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'wasm', attribute 'org.jetbrains.kotlin.js.public.package.json' with value 'public-package-json', attribute 'org.jetbrains.kotlin.wasm.target' with value 'js' but:
         - Variant 'commonFakeApiElements-published' capability com.squareup.okio:okio-nodefilesystem:3.9.0:
             - Incompatible because this component declares a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a component for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'wasm'
             - Other compatible attributes:
                 - Doesn't say anything about its component category (required a library)
                 - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                 - Doesn't say anything about org.jetbrains.kotlin.js.public.package.json (required 'public-package-json')
                 - Doesn't say anything about org.jetbrains.kotlin.wasm.target (required 'js')
         - Variant 'jsApiElements-published' capability com.squareup.okio:okio-nodefilesystem:3.9.0 declares a library:
             - Incompatible because this component declares a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'wasm'
             - Other compatible attributes:
                 - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                 - Doesn't say anything about org.jetbrains.kotlin.js.public.package.json (required 'public-package-json')
                 - Doesn't say anything about org.jetbrains.kotlin.wasm.target (required 'js')
         - Variant 'jsRuntimeElements-published' capability com.squareup.okio:okio-nodefilesystem:3.9.0 declares a library for use during 'kotlin-runtime':
             - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'wasm'
             - Other compatible attributes:
                 - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                 - Doesn't say anything about org.jetbrains.kotlin.js.public.package.json (required 'public-package-json')
                 - Doesn't say anything about org.jetbrains.kotlin.wasm.target (required 'js')
         - Variant 'jsSourcesElements-published' capability com.squareup.okio:okio-nodefilesystem:3.9.0 declares a component for use during 'kotlin-runtime':
             - Incompatible because this component declares documentation, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'wasm'
             - Other compatible attributes:
                 - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                 - Doesn't say anything about org.jetbrains.kotlin.js.public.package.json (required 'public-package-json')
                 - Doesn't say anything about org.jetbrains.kotlin.wasm.target (required 'js')

Which kind of makes sense.

Is there any option for wasmJs to read from real fs the same way it works for js targets?

@swankjesse
Copy link
Collaborator

Try wasmWasi ?

@swankjesse
Copy link
Collaborator

We expose the Node FileSystem in Kotlin/JS only. For WASM we have the WASI FileSystem, which is needs its directories to be specified.

@JakeWharton
Copy link
Collaborator

JakeWharton commented Apr 2, 2024

Or if you're in a browser you have to use the JS file system API directly and can't use Okio: https://developer.mozilla.org/en-US/docs/Web/API/File_System_API. In that case you can wrap your file system interactions in a higher-level suspending interface and switch between Okio and native JS implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants