Sorry for yet another JS question, but I’ve been banging my head against the wall on this for a couple hours.
Svelte is a framework for SPAs vaguely like React, for the sake of this question. Svelte components are .html files that can contain JS. I thought it would be neat if these JS modules could consume Kotlin generated in the same module. I’m also using Rollup.
I’ve tried every conceivable import statement:
<script>
import "./myModule";
import "./my-module";
import "./myModule.js";
import "./my-module.js";
</script>
(where my module is actually called my-module
)
And various permutations prefixed with ../
, but I always get
Error: Could not resolve './my-module' from src\main\svelte\App.html
at error (C:\Users\[me]\Documents\[project]\[my-module]\node_modules\rollup\dist\rollup.js:3438:30)
or something similar.
Importing build/kotlin-js-dce/main/my-module.js
resolves, but doesn’t actually appear to export anything – perhaps because it’s a CommonJS module. Perhaps as a workaround I could invoke Rollup twice (once to convert completely from CommonJS to ESM) but that seems like it should be unnecessary.
A stripped-down version of my rollup.config.js looks like this:
let includePathOptions = {
include: {},
paths: ['src/main/svelte', 'src/main/kotlin'],
external: [],
extensions: []
};
export default {
external: ['kotlin'],
output: {
format: "iife",
name: "app",
sourcemap: true,
globals: { "kotlin": "kotlin" }
},
plugins: [
includePaths(includePathOptions),
commonjs(),
svelte({
include: ['src/main/svelte/**.html']
})
]
}
But I don’t think this is actually Svelte-related, since the exception comes through Rollup (Svelte is requesting a module from Rollup which apparently can’t be found).
If anyone has gotten this or something like this to work, please let me know! Thanks!