Florent Martin
01/07/2025, 11:00 AMArtem Kobzar
01/07/2025, 11:17 AMIlya Goncharov [JB]
01/07/2025, 11:23 AMExec
task type of Gradle.
I am not sure that I understand your setup.
How do you declare NPM dependency in Gradle?
You can use something like with File
implementation(npm(projectDir.resolve("your-package")))
Florent Martin
01/07/2025, 2:30 PMimplementation(npm(File(pathToLocalNpmModule.absolutePath)))
` in Order to use it (via a kotlin-wrapper) in kotlinJS-Frontend.
We figured out that new changes in the typescript-library won’t be taken by the kotlinJs-Frontend because the frontend seems to use the yarn-cache even if we change the typescript-library-version (package.json) and run the gradle-task “kotlinUpgradeYarnLock”.
The only way to be sure that the kotlinJs-Frontend is up-to-date is to run “gradle clean” (or eventually remove the “node_modules” folder in the kmp-build).
That’s why we think that we need to clear the yarn-cache before building our kotlinJs-FrontendIlya Goncharov [JB]
01/07/2025, 4:59 PMyarn.lock
file).
After task kotlinNpmInstall
task was executed, your library in node_modules
should be updated.
kotlinNpmInstall
always is up-to-date
, so it should aware about changes in local dependencies.
I tried it in some sample, and just created folder with package.json
and foo.js
And use
implementation(npm(projectDir.resolve("foo")))
And every change can be seen after task kotlinNpmInstall
Florent Martin
01/07/2025, 5:24 PMkotlinNpmInstall
should not be up-to-date
in Order to be run. Btw, I never succeeded in forcing kotlinNpmInstall
not to be up-to-date
, this is something I actually thought would do the trick. Is there a way?
I changed our implementation for “projectDir.resolve(“foo”)” and it looks better.Ilya Goncharov [JB]
01/07/2025, 5:26 PMkotlinNpmInstall
with up-to-date state?Florent Martin
01/07/2025, 5:28 PMFlorent Martin
01/08/2025, 10:47 AMkotlinNpmInstall
is most of the time up-to-date?
Do you need more infos about the setup?
Is there a way to force the kotlinNpmInstall
before running frontendProcessResources
?Florent Martin
01/08/2025, 10:52 AMFlorent Martin
01/08/2025, 11:08 AM:kotlinNpmInstall --rerun-tasks
before frontendBrowserDevelopmentRun
or frontendBrowserProductionRun
but this do not update my local typescript-library in node_modules
only a `gradle clean`will do itIlya Goncharov [JB]
01/08/2025, 11:34 AMDo you need more infos about the setup?I think, yes. If it is possible I’d like to take a look on minimal reproducer (like, for example easy JS library -
package.json
and one js file), and main Kotlin module with build.gradle.kts
where you have NPM dependency on this easy JS packageIlya Goncharov [JB]
01/08/2025, 11:40 AMIlya Goncharov [JB]
01/08/2025, 12:06 PMbuild/js/package.json
we declare workspaces as all Gradle modules, so we could add your NPM package to workspace list.
But I can recommend you to try NPM package manager instead of Yarn. NPM processes file dependency as a symlink while Yarn just copies dependency to node_modules
To try it you can switch property in gradle.properties
kotlin.js.yarn=false
Florent Martin
01/09/2025, 9:49 AM"packages/myproject-frontend-frontend": {
"dependencies": {
"library": "file:/Users/myname/myproject/typescript/library",
`
If I deploy this, I always get an Execution failed for task kotlinStorePackageLock.
Lock file was changed. Run the kotlinUpgradePackageLock task to actualize lock file
error
Do you think there is a way to fix that?
Is this the reason why you actually use yarn as dependency manager?
Thank youEdoardo Luppi
01/09/2025, 10:36 AMimplementation(npm(File(pathToLocalNpmModule.absolutePath)))
which resolves to an absolute path. You need a relative one.Edoardo Luppi
01/09/2025, 10:40 AMIs this the reason why you actually use yarn as dependency manager?AFAIK the use of Yarn Classic is just historical. npm has been getting better lately and that's why support was implemented.
Edoardo Luppi
01/09/2025, 10:42 AMIlya Goncharov [JB]
01/09/2025, 11:09 AMIs this the reason why you actually use yarn as dependency manager?NPM still have some issues around workspaces usage and stability of
package-lock.json
ю
it would be nice to have a plugin system for package managers so that we’re able to customize package resolutionSo actually it has proto extensibility, because both Yarn and NPM are now supported through common interfaces, and not hard coded into KGP
Florent Martin
01/09/2025, 1:07 PMimplementation(npm(pathToLocalNpmModule))
which I now use.
Do you have any code-example where I can just give the absolute path?Florent Martin
01/09/2025, 6:31 PMIlya Goncharov [JB]
01/10/2025, 10:13 AMrootPackageJson
which produces build/js/package.json
where all workspaces are declared
So in doLast
block you can change content of the task
tasks.named("rootPackageJson").configure {
doLast {
// change content of the package.json
}
}
Florent Martin
01/10/2025, 10:39 AMimplementation(npm(pathToLocalNpmModule))
use an absolute path, which is not ok for my deployment-process.
Do you evtl. know a way to define a relative File path there?Ilya Goncharov [JB]
01/10/2025, 10:57 AMEdoardo Luppi
01/10/2025, 10:58 AMEdoardo Luppi
01/10/2025, 10:58 AMIlya Goncharov [JB]
01/10/2025, 11:01 AMbuild.gradle(.kts)
file, but package.json
is hosted in another place (build/js/<package>/package.json
). So anyway we need to align this path, but I think relative path sounds more logicalEdoardo Luppi
01/10/2025, 11:02 AMIlya Goncharov [JB]
01/10/2025, 11:06 AMEdoardo Luppi
01/10/2025, 11:06 AMFlorent Martin
01/10/2025, 11:52 AMEdoardo Luppi
01/11/2025, 11:21 AMFlorent Martin
01/13/2025, 6:02 AMtasks.named("rootPackageJson").configure {
doLast {
// change content of the package.json
}
}
We always get Task with name 'rootPackageJson' not found in root project
.Ilya Goncharov [JB]
01/13/2025, 11:01 AMNodeJsRootPlugin
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
rootProject.tasks.named("rootPackageJson").configure {
}
}
Florent Martin
01/13/2025, 3:11 PMpackage-lock.json
in a task in Order to commit it or will it always be automatically overwritten?
Something like:
rootProject.tasks.named("kotlinStorePackageLock").configure {
doLast {
overwriteMyPackageLockWithRelative
}
}
Edoardo Luppi
01/13/2025, 3:13 PMpackage.json
Florent Martin
01/13/2025, 3:44 PMEdoardo Luppi
01/13/2025, 3:46 PMpackage.json
file, and not package-lock.json
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
rootProject.tasks.named("rootPackageJson").configure {
doLast { ... }
}
}
Florent Martin
01/15/2025, 9:09 AMTypeError: Cannot read properties of null (reading 'useState')
but not during development.
In my custom library, I added react as a peerDependency. I am using vite and it is alsi set as external in my rollupOptions:
rollupOptions: {
external: [
'react',
'react-dom',
'react/jsx-runtime',
and is also in resolve.dedupe:
resolve: {
dedupe: ['react', 'react-dom'],
but I keep having the error.
Did you already had this kind of problems @Ilya Goncharov [JB]?Florent Martin
01/16/2025, 1:39 PMbuild/js/package.json
workspaces as "../../mylibrary"
, it doesnt seem to change anything so that I still have to run gradle clean
in Order to see the library-changes in kotlinJS.
@Ilya Goncharov [JB] Am I missing something?Ilya Goncharov [JB]
01/16/2025, 9:26 PMnode_modules
should be linked with your libraryFlorent Martin
01/17/2025, 9:57 AMgradle clean
anymore,Florent Martin
01/21/2025, 3:44 PMbuild/js/node_modules
but it is also present in build/js/packages/myfrontend/node_modules/myModule
and the frontend use this instead of the symlink.
@Ilya Goncharov [JB] Any idea what could cause that?Florent Martin
01/21/2025, 4:21 PMimplementation(npm(pathToLocalNpmModule))
and as you advised via workspaces. Adding it only via workspaces does the trickEdoardo Luppi
01/21/2025, 4:22 PMFlorent Martin
01/21/2025, 4:23 PMFlorent Martin
02/10/2025, 8:46 AMIlya Goncharov [JB]
02/10/2025, 10:01 AMArtem Kobzar
02/10/2025, 10:14 AMEdoardo Luppi
02/10/2025, 10:21 AMWe just realized that Experimental means “try it only in toy projects”My 2c: basically everyone likes the current JS export model, and everyone I know has been using it by opting in via Gradle for convenience. There has been some criticism about having to annotate every public declaration in certain cases, but that can be probably solved via KGP's DSL in the future. I think you shouldn't worry too much about using it.
Florent Martin
02/10/2025, 3:14 PM