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

File resource in web triggers SyntaxError #754

Open
codlab opened this issue Aug 19, 2024 · 1 comment
Open

File resource in web triggers SyntaxError #754

codlab opened this issue Aug 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@codlab
Copy link

codlab commented Aug 19, 2024

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)
@Alex009
Copy link
Member

Alex009 commented Sep 7, 2024

hi. looks like current implementation of files on js is invalid for some types.

i see that in example we use simple txt and that works. but maybe for yml webpack do some extra actions.

https://github.com/icerockdev/moko-resources/blob/master/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/files/some_file.txt

if you know how files should be fixed - please describe, it will help

@Alex009 Alex009 added the bug Something isn't working label Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants