mpetuska / npm-publish

Gradle plugin for NPM package publishing. Allows for arbitrary publishing as well as seamless integration with Kotlin JS/MPP plugins.
https://npm-publish.petuska.dev
Apache License 2.0
126 stars 10 forks source link

fs, path problem #166

Closed Lukaszz112 closed 5 months ago

Lukaszz112 commented 5 months ago

I use in my common lib sqldelight and kottage wchich probably requires fs on other platforms, how can i config it to hide this errors on web browser?

cause of binaries.library() doesnt have browserProductionWebpack task

mpetuska commented 5 months ago

I'm gonna need some logs to assist.

Lukaszz112 commented 5 months ago
Compiled with problems:X

WARNING in ../../node_modules/better-sqlite3/lib/database.js 50:10-81

Critical dependency: the request of a dependency is an expression

ERROR in ../../node_modules/better-sqlite3/lib/database.js 2:11-24

Module not found: Error: Can't resolve 'fs' in '(projectdir)/build/js/node_modules/better-sqlite3/lib'

ERROR in ../../node_modules/better-sqlite3/lib/database.js 3:13-28

Module not found: Error: Can't resolve 'path' in '(projectdir)/build/js/node_modules/better-sqlite3/lib'

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.

Something like that.

mpetuska commented 5 months ago

AH, right. This has nothing to do with this plugin, but there are way people have managed to go around this issue.

What you need to do is basically copy ktor's strategy and rely on dynamic types and loading the dependency via js("require('fs')") and checking for window == undefined beforehand to detect browser environment. For some node dependencies you could find browser polyfills.

See https://youtrack.jetbrains.com/issue/KT-47038 for a wider discussion.