moko-resources
moko-resources copied to clipboard
File resource in web triggers SyntaxError
I'm using the versions 0.24.1 of the library and I'm currently facing an exception on js specifically (the other platforms works as expected).
I have yamls files in commonMain/moko-resources folder and seems ok from the generation's perspective (as from the tests on android, iOS & JVM flavours). However the tests I'm running won't work when used from jsMain (cf the stack trace posted below).
It's likely that the files are being loaded as pure javascript files from the resulting bundled as Moko-resources's generated implementation is giving the following:
public actual object Resources {
...
public actual object files : ResourceContainer<FileResource> {
public actual override val __platformDetails: ResourcePlatformDetails =
ResourcePlatformDetails()
public actual val classifications_yml: FileResource = FileResource(fileUrl =
js("require(\"./files/classifications.yml\")") as String)
...
}
My knowledge in webpack is very shallow but could it be that the generated generated file is improperly registering those files and let webpack think it should find regular javascript files and not ressources ? path.resolve(__dirname, "kotlin/files") kotlin/files doesn't exist, yet it's referenced by moko-resources-generated.js as available here
SyntaxError: Unexpected token ':'
path/to/the/lib/js/packages/lorcana-data-lorcana-data-test/kotlin/files/classifications.yml:1
- slug: song
SyntaxError: Unexpected token ':'
at <global>.wrapSafe(node:internal/modules/cjs/loader:1357)
at Module._compile(node:internal/modules/cjs/loader:1414)
at Object.Module._extensions..js(node:internal/modules/cjs/loader:1534)
at Module.load(node:internal/modules/cjs/loader:1265)
at Function.Module._load(node:internal/modules/cjs/loader:1081)
at Module.require(node:internal/modules/cjs/loader:1290)
at <global>.require(node:internal/modules/helpers:188)
at <global>.new files(path/to/the/lib/build/generated/moko-resources/jsMain/src/eu/codlab/lorcana/resources/Resources.kt:18)
at <global>.files_getInstance(kotlin/lorcana-data-lorcana-data.js:236)
at <global>.new Abilities(path/to/the/lib/src/commonMain/kotlin/eu/codlab/lorcana/Abilities.kt:15)
at <global>.Abilities_getInstance(kotlin/lorcana-data-lorcana-data.js:256)
at slambda.protoOf.doResume_5yljmg(path/to/the/lib/src/commonTest/kotlin/eu/codlab/lorcana/TestLoadingAbilities.kt:29)
at slambda.protoOf.invoke_blawzt(kotlin/lorcana-data-lorcana-data-test.js:476)
at slambda.$testBody(kotlin/lorcana-data-lorcana-data-test.js:535)
at slambda.protoOf.doResume_5yljmg(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:316)
at slambda.protoOf.resumeWith_b9cu3x(/Users/kevinleperfpath/to/the/lib/build/compileSync/js/test/testDevelopmentExecutable/kotlin/src/kotlin/util/Standard.kt:50)
at slambda.protoOf.resumeWith_dtxwbr(kotlin/kotlin-kotlin-stdlib.js:11425)
at DispatchedContinuation.protoOf.run_mvkpxh(path/to/the/lib/build/compileSync/js/test/testDevelopmentExecutable/kotlin/src/kotlin/coroutines/Continuation.kt:45)
at StandardTestDispatcherImpl.protoOf.processEvent_53mmqp(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestDispatcher.kt:24)
at TestCoroutineScheduler.protoOf.tryRunNextTaskUnless_463vnb(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestCoroutineScheduler.kt:99)
at slambda_1.protoOf.doResume_5yljmg(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:322)
at slambda_1.protoOf.invoke_d9fzmj(kotlin/kotlinx-coroutines-test.js:377)
at <global>.l(kotlin/kotlinx-coroutines-test.js:453)
at _no_name_provided__qut3iv_7.protoOf.doResume_5yljmg(path/to/the/lib/build/compileSync/js/test/testDevelopmentExecutable/kotlin/js/src/kotlin/coroutines/intrinsics/IntrinsicsJs.kt:161)
at _no_name_provided__qut3iv_7.protoOf.resumeWith_b9cu3x(path/to/the/lib/build/compileSync/js/test/testDevelopmentExecutable/kotlin/src/kotlin/util/Standard.kt:50)
at _no_name_provided__qut3iv_7.protoOf.resumeWith_dtxwbr(kotlin/kotlin-kotlin-stdlib.js:11425)
at DispatchedContinuation.protoOf.run_mvkpxh(path/to/the/lib/build/compileSync/js/test/testDevelopmentExecutable/kotlin/src/kotlin/coroutines/Continuation.kt:45)
at ScheduledMessageQueue.protoOf.process_myqcf5(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/jsAndWasmShared/src/internal/JSDispatcher.kt:127)
at <global>.<unknown>(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/js/src/JSDispatcher.kt:21)
at <global>.processTicksAndRejections(node:internal/process/task_queues:77)