# Issues about IDEA support of Kotlin script (.kts)

**URL:** <https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386>\
**Category:** Support\
**Created:** [January 26, 2018, 6:17am UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386 "2018-01-26T06:17:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ckchen](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@ckchen](https://discuss.kotlinlang.org/u/ckchen)\
**Post date:** [January 26, 2018, 6:17am UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386/1 "2018-01-26T06:17:58Z")

</div>

By creating a .kts file and copying the code snippet at [https://kotlinlang.org/docs/tutorials/command-line.html#using-the-command-line-to-run-scripts](https://kotlinlang.org/docs/tutorials/command-line.html#using-the-command-line-to-run-scripts) into it, the editor marks “args” as an error but the code can be run correctly.

Did I miss some settings or it’s a small bug of IDEA?

Also, the debug icon is de-activated. Will it be enabled in the future?

Thanks.

This is the version I used:  
IntelliJ IDEA 2017.3.3 (Ultimate Edition)  
Build #IU-173.4301.25, built on January 16, 2018  
JRE: 1.8.0\_152-release-1024-b11 x86\_64  
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o  
Mac OS X 10.13.2

---

<div class="post-metadata">

**Author:** ![sartan](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sartan](https://discuss.kotlinlang.org/u/sartan)\
**Post date:** [February 17, 2018, 2:17am UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386/2 "2018-02-17T02:17:50Z")

</div>

I’m able to run (though not debug) \*.kts files through IntelliJ.

I installed the Kotlin compiler via homebrew. I also had to specify a JDK in the project configuration as one was not configured by default. Here’s the version info:

```auto
$ kotlinc -version
info: kotlinc-jvm 1.2.21 (JRE 1.8.0_152-b16)

```

```auto
IntelliJ IDEA 2017.3.4 (Ultimate Edition)
Build #IU-173.4548.28, built on January 29, 2018
JRE: 1.8.0_152-release-1024-b11 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.13.3

```

Also, the sample code snippet takes a directory as an argument, so you’ll want to provide that as program argument in the run configuration.

---

<div class="post-metadata">

**Author:** ![tkeber](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/tkeber/32/4801_2.png) [@tkeber](https://discuss.kotlinlang.org/u/tkeber)\
**Post date:** [February 20, 2018, 3:08pm UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386/3 "2018-02-20T15:08:29Z")

</div>

I experience the same as ckchen with these versions

```auto
➜ tmp kotlinc -version
info: kotlinc-jvm 1.2.21 (JRE 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)

```

```auto
IntelliJ IDEA 2017.3.4 (Ultimate Edition)
Build #IU-173.4548.28, built on January 29, 2018

JRE: 1.8.0_152-release-1024-b11 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-32-generic

```

The script does run fine, the problem is that IDEA does not validate the code correctly and falsely reports 4 errors in 3 lines of code:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/5/5e07628f3e56e12f6225f53fddad2615cade37ad.png)

Is this a configuration problem? Do we miss some settings?

Also, in scripting I want to pass exit codes to the calling shell to indicate success or failure of the script run. I tried to do that with exitProcess ([exitProcess - Kotlin Programming Language](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.system/exit-process.html)), but that reults in `error: unresolved reference: exitProcess`. What is the recommended way to return an exit code from a kotlin script?

Thanks,  
Thilo

---

<div class="post-metadata">

**Author:** ![reitzig](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/reitzig/32/6970_2.png) [@reitzig](https://discuss.kotlinlang.org/u/reitzig)\
**Post date:** [February 21, 2018, 7:32am UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386/4 "2018-02-21T07:32:55Z")

</div>

> [@tkeber](#):
>
> What is the recommended way to return an exit code from a kotlin script?

Does `System.exit(n)` not work?

---

<div class="post-metadata">

**Author:** ![tkeber](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/tkeber/32/4801_2.png) [@tkeber](https://discuss.kotlinlang.org/u/tkeber)\
**Post date:** [February 21, 2018, 9:51am UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386/5 "2018-02-21T09:51:49Z")

</div>

Thanks, @reitzig! Your reply solved both of my problems:

1. As of this morning I cannot reproduce any more the IDE problem. The errors in IDEA have disappeared magically (on my Linux installation as well as on Windows. 🧙)

2. yes, `System.exit(n)` works, as well as `exitProcess(n)`, where now IDEA kindly offers to add

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [February 21, 2018, 11:13am UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386/6 "2018-02-21T11:13:47Z")

</div>

> [@tkeber](#):
>
> As of this morning I cannot reproduce any more the IDE problem. The errors in IDEA have disappeared magically (on my Linux installation as well as on Windows. 🧙)

Sometimes just restarting helps 😉

---

<div class="post-metadata">

**Author:** ![ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@ivan](https://discuss.kotlinlang.org/u/ivan)\
**Post date:** [August 15, 2018, 2:25pm UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386/7 "2018-08-15T14:25:31Z")

</div>

In my case this appears in the errors too:

Error:(3, 1) Kotlin: Cannot access script base class ‘kotlin.script.templates.standard.ScriptTemplateWithArgs’. Check your module classpath for missing or conflicting dependencies

Running the script from the command line is fine.

Also tried restarting IntelliJ (with invalidate caches)

---

<div class="post-metadata">

**Author:** ![reitzig](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/reitzig/32/6970_2.png) [@reitzig](https://discuss.kotlinlang.org/u/reitzig)\
**Post date:** [August 31, 2018, 7:06am UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386/8 "2018-08-31T07:06:15Z")

</div>

`exitProcess` is indeed the better choice since it has return type `Nothing` (instead of `void`).

---

<div class="post-metadata">

**Author:** ![jarekczeking](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@jarekczeking](https://discuss.kotlinlang.org/u/jarekczeking)\
**Post date:** [January 25, 2019, 6:32pm UTC](https://discuss.kotlinlang.org/t/issues-about-idea-support-of-kotlin-script-kts/6386/9 "2019-01-25T18:32:59Z")

</div>

I was able to fix kts problems in Intellij 2017.3 by moving my kts files into the main directory. That is into a directory that belongs to some module. When they were outside of modules (in root directory), the syntax errors were appearing.
