how do I access `process` from nodejs? It seems th...
# javascript
r
how do I access
process
from nodejs? It seems that my kotlinjs in general is very browser-centric, which is kind of frustrating πŸ˜•
r
r
looks interesting, do I just import, or do I need to use it as a gradle plugin?
r
Just add as a dependency and you should have all nodejs declarations ready to use
r
will give it a try, thanks
when I'm using it I get:
When accessing module declarations from UMD, they must be marked with both @JsModule and @JsNonModule.
c
whats your version of the
multiplatform
plugin?
r
I think the declarations are designed to work with
useEsModules()
option
πŸ‘Œ 1
r
I'll see if that works, I must admit that JS/TS and the various import schemes have always been slightly confusing to me
@Chrimaeon 2.1.0
πŸ‘πŸΌ 1
@Robert Jaros well now it compiles, but ofc the wrappers I already have is now broken
Copy code
Error: Cannot find module '/home/rohdef/git/action-build-container-source/build/js/node_modules/@docker/actions-toolkit/lib/github' imported from /home/rohdef/git/action-build-container-source/build/js/packages/action-build-container/kotlin/action-build-container.mjs
Did you mean to import "@docker/actions-toolkit/lib/github.js"?
the error I get on the existing imports are like this one. I guess it could change it to refer to the
.js
files, but isn't that kind of wrong to do?
and when running it doing that I get:
Copy code
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/work/_actions/rohdef/action-build-container/main/node_modules/action-build-container/kotlin/action-build-container.mjs not supported.
Instead change the require of /home/runner/work/_actions/rohdef/action-build-container/main/node_modules/action-build-container/kotlin/action-build-container.mjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/runner/work/_actions/rohdef/action-build-container/main/index.js:5:1) {
  code: 'ERR_REQUIRE_ESM'
}
it is not happy with me
r
Sorry for that. I really thought kotlin-node project will just work for you.
r
no worries, it was worth a shot πŸ™‚
c
and you have configured your target as
nodeJs
and not
browser
?
e
You need to configure a module type,
useCommonJs()
or
useEsModules()
Ah you've already figured it out. I guess you'll have to fix your own wrappers unfortunately 😞
r
Perhaps it will work with
useCommonJs()
(it should allow
require
, shouldn't it?)
e
Yup in that case CommonJS is the right pick.
t
I really thought kotlin-node project will just work for you.
@Robert Jaros we had no control under project dependencies πŸ˜‰.
kotlin-node
support both ESM and CommonJS. ESM - default recommendation, because it works everywhere (Browser, Node, Deno) and it's future default/single Kotlin/JS option. CommonJS - can be used if you have problems with dependencies. Node
23.5.0
already contains pills for mixed projects. AFAIK @Vampire has pills for CommonJS dependencies in ESM project πŸ˜‰
Choose dependencies with compatible module system and/or bundler configuration - developer responsibility πŸ™‚
v
Do I? :-D
I just used some case by case regex replacements for specific cases that you gave me. :-)
😜 1
r
@Chrimaeon yes, I only configured for nodejs, no browser anywhere πŸ™‚
@Edoardo Luppi curious, what is the default if neither is set? That was my point of origin that I more or less reverted to
so if I read the thread right, I should be able to make it work using
useCommonJs
, but in actuality
useESModules
would be better, if I can figure out to rework that wrappers I already have?
the
useCommonJs
-approach works πŸ™‚
πŸ‘ 1
v
As far as I understood it, ESM is "the new way" and also the default for normal node js modules. Some dependencies I used were only ESM-compatible in latest version, so I forcibly had to switch to ESM to use the new version.
e
Node.js predominantly uses CJS, but it can now operate both, and at the same time, with mostly no issues on the ESM side. Still CJS is what most packages are using.
@Rohde Fischer the default is UMD
The fact ESM still isn't widely used on Node projects is also why I've been pushing for a split between Node and browser in MPP, so that we can configure different module types based on the target.