Description
I was getting the following error when trying to use vue.js composables and import a script js file.
'import' and 'export' may appear only with 'sourceType: "module"' (1:0)
I have tried to replicate the solutions here:
#44 and here
#14 (comment)
Specifically this solution:
async getFile(url) {
const res = await fetch(url);
if (!res.ok) throw Object.assign(new Error(url + " " + res.statusText), { res });
let content = await res.text();
content = url.endsWith("/test.js") ? { content: content, type: ".mjs" } : content;
return content;
},
Where the test.js file is :
export const user = {
userName: "root",
password: "zfs1111"
}
is giving me the error: TypeError: t is not a function in the console. I get the same error trying to import a non-test js file.
Is this an old solution that is no longer viable? What is the new solution if yes?
using Vue3.js
Versions
- Browser (name & version):
- vue3-sfc-loader:
Additional context
Activity
FranckFreiburger commentedon Nov 22, 2024
hello SMen1,
yes, the solution you are talking about is quite old
{ content: content, type: ".mjs" }
is not valid any more.In order to handle binary files (ex. png) I managed to change 'content' property into
getContentData: (asBinary: Boolean) => Promise<ContentData>
Now, your
option.getFile
function should look like this: