Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: module is not defined #36

Closed
McPringle opened this issue Feb 11, 2018 · 9 comments
Closed

Uncaught ReferenceError: module is not defined #36

McPringle opened this issue Feb 11, 2018 · 9 comments

Comments

@McPringle
Copy link

When I include kotlin-extensions in my HTML page, I get this error in all browsers:

Uncaught ReferenceError: module is not defined
    at kotlin-extensions.js:93
(anonymous) @ kotlin-extensions.js:93

This is line 93:

}(module.exports, require('kotlin'), require('core-js/library/fn/object/assign')));

The kotlin module is loaded, but core-js seems new to me. I could not find any documentation in the kotlin-extensions project which mentions core-js. As I include kotlin-extensions via gradle and I can not find anything core-js releated in the project, I assume the kotlin-extensions artifact is missing the dependency to core-js.

dependencies {
    compile(
        "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion",
        "org.jetbrains:kotlin-extensions:$kotlinExtensionsVersion",
        "org.jetbrains:kotlin-react:$kotlinReactVersion",
        "org.jetbrains:kotlin-react-dom:$kotlinReactVersion"
    )
}
@Hypnosphi
Copy link
Contributor

core-js is an npm dependency of @jetbrains/kotlin-react-dom package, so you may need to run npm install in its directory

@McPringle
Copy link
Author

Hi @Hypnosphi

Thank you very much for your answer. The require comes from the kotlin-extensions source code. I can't run a npm install because there is no npm configuration in the project. I use gradle to manage the dependencies and to build the project (see bintray.com). If core-js is a dependency of kotlin-extensions I would assume that gradle is going to download that, too. But in fact it is not downloading core-js, so I assume that this dependency is not mentioned in the artifact metadata.

@McPringle
Copy link
Author

Please take a look at the pom of kotlin-extensions:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.jetbrains</groupId>
  <artifactId>kotlin-extensions</artifactId>
  <version>1.0.0-pre.19-kotlin-1.2.20</version>
  <dependencies>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib-js</artifactId>
      <version>1.2.20</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlinx</groupId>
      <artifactId>kotlinx-html-js</artifactId>
      <version>0.6.8</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>
</project>

The dependency to core-js is missing there. The core-js library is used in Object.kt line 39:

@JsModule("core-js/library/fn/object/assign")
external fun <T, R : T> assign(dest: R, src: T): R

@Hypnosphi
Copy link
Contributor

@Leonya how do you handle this issue?

@Leonya
Copy link
Collaborator

Leonya commented Feb 17, 2018

@Hypnosphi we have it added into the project package.json

@andrasferenczi
Copy link

Is it possible that this issue still exists?

Gradle:

compile 'org.jetbrains:kotlin-extensions:1.0.1-pre.28-kotlin-1.2.30'

And the error:

Uncaught ReferenceError: module is not defined
    at kotlin-extensions.js:111

The line is this:

}(module.exports, require('kotlin'), require('core-js/library/fn/object/assign')));

@Leonya
Copy link
Collaborator

Leonya commented May 16, 2018

It does exist, you have to npm install core-js. If you're not using npm we don't have a solution at the moment, I'm afraid.

@n3phtys
Copy link

n3phtys commented Dec 24, 2018

It sucks that this cannot yet be solved without npm.
I started using the frontend plugin to do my multiplatform build with a kotlin-react frontend: https://github.com/Kotlin/kotlin-frontend-plugin
That way you can wrap npm with gradle and your build.gradle and install all dependencies (including core-js) locally. And you get Webpack bundling for free if you use the plugin, meaning the end result will be a single js file (that is served by ktor in my case).

Still, it's definitely less than optimal that we need to use npm for even simple Kotlin projects thanks to this issue. Maybe it makes sense to release a "fat" extensions-file that includes core-js.

@Hypnosphi
Copy link
Contributor

I'm going to drop the core-js import. Make sure that you provide your own Object.assign polyfill if you're using objectAssign and have to support IE11

@Leonya Leonya closed this as completed Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants