Hi everyone, I’m trying to use okio for kotlinJS b...
# javascript
f
Hi everyone, I’m trying to use okio for kotlinJS browser, and it doesn’t work, did I miss something? okio: 3.9.1 kotlin: 2.1.0
Copy code
Module not found: Error: Can't resolve 'fs' in '.../build/js/packages/ktorfilecaching-test/kotlin'
Module not found: Error: Can't resolve 'path' in '.../build/js/packages/ktorfilecaching-test/kotlin'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
	- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "path": false }
Module not found: Error: Can't resolve 'os' in '/Users/francoisdabonot/DEV/KtorKMPFileCaching/build/js/packages/ktorfilecaching-test/kotlin'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
	- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "os": false }
c
it does not work on browsers - there is no files api on browsers. it only work on node.js https://square.github.io/okio/multiplatform/#file-system
f
So, how to separate Browser and NodeJS implementation?
c
create separate modules, on for browser and one for node.
f
I see, the hard way 😄 An issue discussing the problem but no solution 😞 https://youtrack.jetbrains.com/issue/KT-47038/KJS-MPP-Split-JS-target-into-JsBrowser-and-JsNode
💯 2
e
@François if you haven't already, upvote it. Sooner or later we might get it.
f
Yes, I did it 😄
gratitude thank you 1
e
f
Yeah , I got that message
Copy code
w: Kotlin Target 'js()' is already declared.

Declaring multiple Kotlin Targets of the same type is not supported.
But it’s still working on kotlin 2.1.0
I’m building a library, so I guess it just works 😄
f
Right, I guess you’re looking for the same solution as me, longer time than me. I’m sticking with my current solution until there is a real one.
e
@hfhbd just FYI, it's still a warning, and not an error as we had discussed. See comments above.
I’m sticking with my current solution until there is a real one
I will probably do the same once I get to the point of targeting the browser.
I have been extremely careful in importing libraries and using externals, for the sake of not having to go crazy at that point.
For example, I'm now using Node.js externals without
@JsModule
, as that creates an AOT import of the module, and immediately breaks on browsers.
f
My project is not so complex, okio + localstorage, that’s all and a lot of copy/paste.