# How can set the scope for the output npm package (i.e. set the package name)?

**URL:** <https://discuss.kotlinlang.org/t/how-can-set-the-scope-for-the-output-npm-package-i-e-set-the-package-name/16335>\
**Category:** JavaScript\
**Created:** [February 14, 2020, 2:31pm UTC](https://discuss.kotlinlang.org/t/how-can-set-the-scope-for-the-output-npm-package-i-e-set-the-package-name/16335 "2020-02-14T14:31:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bradleycorn](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/bradleycorn/32/7250_2.png) [@Bradleycorn](https://discuss.kotlinlang.org/u/Bradleycorn)\
**Post date:** [February 14, 2020, 2:31pm UTC](https://discuss.kotlinlang.org/t/how-can-set-the-scope-for-the-output-npm-package-i-e-set-the-package-name/16335/1 "2020-02-14T14:31:55Z")

</div>

I have a fairly standard Kotlin Multiplatform library project that produces library targets for android, jvm, and JavaScript. My project includes a single module, let’s call it ‘my-module’. When I assemble the project, I wind up with a publish-able npm package in the build/js/packages/my-module directory. The produced package.json looks like this:  
{  
“main”: “kotlin/my-module.js”,  
“devDependencies”: {},  
“dependencies”: {  
“webpack”: “4.29.6”,  
“webpack-cli”: “3.3.0”,  
“source-map-loader”: “0.2.4”,  
“source-map-support”: “0.5.12”,  
“webpack-dev-server”: “3.3.1”,  
“kotlin”: “1.3.41”  
},  
“name”: “my-module”,  
“version”: “1.0.20”  
}

I want to publish this package to my organization’s npm registry. However, the registry requires that the package name in the package.json be scoped to the organization. So, in the package.json, the name should be:  
“name”: “@my-organization/my-module”

Is there some way I can achieve this with a setting in my gradle configuration so that at compile-time the package.json gets produced with the correct scoped name?

---

<div class="post-metadata">

**Author:** ![gciatto-unibo](https://avatars.discourse-cdn.com/v4/letter/g/7feea3/32.png) [@gciatto-unibo](https://discuss.kotlinlang.org/u/gciatto-unibo)\
**Post date:** [April 10, 2020, 7:47am UTC](https://discuss.kotlinlang.org/t/how-can-set-the-scope-for-the-output-npm-package-i-e-set-the-package-name/16335/2 "2020-04-10T07:47:47Z")

</div>

I’m facing the same issue in my multi-platform project.  
I made some custom plugins to alter the generated package.json to include my organization name plus some other info.  
However I noticed this is not sufficient in the case one is making a multi-project build were some js-project must be a dependency for some other js-project.  
This happens because the many `require("other-js-project")` generated by the kotlin compiler in the js sources will still reference any other project without taking care of specifying the organization.

I believe the kotlin plugin for gradle should be extended to support this feature.

However, if you only need to inject an organization name into a single kt-js project, my solution should be fine:

- I defined some tasks in my buildSrc: [https://gitlab.com/pika-lab/tuprolog/2p-in-kotlin/-/tree/feature/js/buildSrc/src/main/kotlin/node](https://gitlab.com/pika-lab/tuprolog/2p-in-kotlin/-/tree/feature/js/buildSrc/src/main/kotlin/node)
- I use them here [https://gitlab.com/pika-lab/tuprolog/2p-in-kotlin/-/blob/feature/js/build.gradle.kts#L386](https://gitlab.com/pika-lab/tuprolog/2p-in-kotlin/-/blob/feature/js/build.gradle.kts#L386)

---

<div class="post-metadata">

**Author:** ![sofzer](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@sofzer](https://discuss.kotlinlang.org/u/sofzer)\
**Post date:** [June 15, 2021, 11:38am UTC](https://discuss.kotlinlang.org/t/how-can-set-the-scope-for-the-output-npm-package-i-e-set-the-package-name/16335/3 "2021-06-15T11:38:56Z")

</div>

Is there any solution here please? I’m facing the same issue  
I always have to use

```auto
let package= require("packageName").com.company.package.ClassName

```

I would like to access directly to the class eg:

```auto
let package= require("packageName").ClassName

```

---

<div class="post-metadata">

**Author:** ![inglettronald](https://avatars.discourse-cdn.com/v4/letter/i/50afbb/32.png) [@inglettronald](https://discuss.kotlinlang.org/u/inglettronald)\
**Post date:** [August 5, 2025, 10:47pm UTC](https://discuss.kotlinlang.org/t/how-can-set-the-scope-for-the-output-npm-package-i-e-set-the-package-name/16335/4 "2025-08-05T22:47:53Z")

</div>

Hey folks,

For anyone who is looking at this much later for some project, I thought I would share my solution to this problem.

In your `build.gradle.kts` file, you can now declare the module name as such:

```auto
kotlin {
     // My project happens to be targetting java and node
     jvmToolchain(21)
     jvm()
     js(IR) {
         binaries.executable()
         nodejs()
         outputModuleName = "@<organization>/<your-project-name>"
     }
 }

```

Looks like this flag got added in 2.1.20 from [[Wasm] Output module name for web targets with Provider API · JetBrains/kotlin@1618143 · GitHub](https://github.com/JetBrains/kotlin/commit/1618143efde19be40462e5fb52d74780eef13cb0), replacing the previous `moduleName` param introduced in [[Gradle, JS] Module name for js · JetBrains/kotlin@5492a93 · GitHub](https://github.com/JetBrains/kotlin/commit/5492a93229388f602ab0fd615b2e33649792502c) (kotlin 1.4).
