Resolving `ext-src` imports in the SDK if the user declares an import with the `.js` ext
Users get a weird error saying they can't import queries.js.js something something.
I've reproduced with the latest Wasp version: 0.13.2
As far as I can see, it seems related to the exports fields and the ext-src/* entry 😄
Two instances on Discord:
- https://ptb.discord.com/channels/686873244791210014/1250145383322091561/1250145383322091561
- https://ptb.discord.com/channels/686873244791210014/1249857194925752401/1249857194925752401
Sending this back to triage, multiple people had this and error message is quite confusing, we should take care of it.
This is in a way related to #2087 , as they might share a solution, which is us completely forbidding, in main.wasp, to have .js or .ts extensions in ext imports, or, another solution, somehow additionally processing extensions to fit with what Wasp requires.
User said following:
Was odd because the issue was nonexistent until one day it wasn't.
That is peculiar! Might it mean that one of the deps updated minor version and caused this that way?
That is peculiar! Might it mean that one of the deps updated minor version and caused this that way?
The error is only triggered when you import an operation from wasp/server/operations into server code that gets used (e.g., the server setup function or an API call). Here's a minimal repro example.
You need the following Wasp file:
app extension {
wasp: {
version: "^0.13.0"
},
title: "example",
server: { setupFn: import { setup } from "@src/setup" }
}
// ...
action jsAction {
fn: import { jsAction } from "@src/jsAction.js"
}
And the following code in setup.js:
import { jsAction } from "wasp/server/operations";
export function setup() {
console.log(jsAction);
}
The error only happens when:
setup.jsimportsjsActionfromwasp/server/operationsmain.waspsomehow usessetup.js.- The
jsActiondeclaration includes a.jsextension in the file name. - The user is using Wasp older than 0.14.0.
If any of the conditions aren't met, there's no error. You need all four to trigger it.
This is probably why our user felt the issue appeared out of thin air - it was caused by something seemingly unrelated.
Since this specific problem was fixed with Wasp 0.14.0 thanks to this change introduced in commit https://github.com/wasp-lang/wasp/pull/1930/commits/c184a9bd23d808475c78fcc75c2f7150b22e8b13, I'm closing the issue.
We still have other extension-related problems which I covered here: #2222.