Guys, I’m trying to run a mpp project with javascr...
# javascript
g
Guys, I’m trying to run a mpp project with javascript and react. My build is going ok but when I open the browser (where the webpack dev server pointed to me) I’m receiving the following error in the console:
Copy code
Uncaught Error: Error loading module 'common'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'common'.
I could see that in my
main.bundle.js
generated file, indeed the
"./common.js"
is being required earlier than the
"./kotlin.js"
module. I tried to change the dependencies order in my
build.gradle.kts
file but it didn’t solve the problem. Does someone knows how can we fix this?
s
Had the same problem but cant remember how we fixed it. Are you using the latest versions of everything?
g
I think yes, at least gradle 5.2+ didn’t work to me. I’m using gradle 5.1.1, kotlin 1.3.21, and frontend plugin with 0.0.45.
Oh, if you remember please tell me, this will help me a lot 😉
s
best I can recall is that the our own module (I guess that is common in your case) didnt require kotlin correctly but assumed it was present in global scope
are you also using
kotlin-dce-js
gradle plugin ?
g
Hum, maybe this is related. My common module is in a different folder and the react project is in another one. I’m using the kotlin-dce-js only in the react module but not in the common module.
s
Ok. I think our problem was that we depended on a kotlin-platform-js based module from a kotlinjs module or something like that and it did not get bundled properly. I never solved that problem so I moved all the js code in the kotlin-platform-js module
g
Oh, I’ve solved it! Thanks @spand. I’ve put this configuration also in my other build.gradle.kts file and it worked 😃
Copy code
js("js") {
		configure(listOf(compilations["main"], compilations["test"])) {
			tasks.getByName(compileKotlinTaskName) {
				kotlinOptions {
					//					languageVersion = "1.3"
					metaInfo = true
//					outputFile = "${project.buildDir.path}/js/${project.name}.js"
					sourceMap = true
					sourceMapEmbedSources = "always"
					moduleKind = "umd"
				}
			}
		}

		configure(listOf(compilations["main"])) {
			tasks.getByName(compileKotlinTaskName) {
				kotlinOptions {
					main = "call"
				}
			}
		}
	}
👍 1