Relative imports in user code combined with imports from wasp/server/operations
break wasp start
#2492
Labels
bug
Something isn't working
This is a problem we've had for a while but haven't properly documented. Users have also been known to hit it (example below).
Steps to reproduce
Create a project with Wasp 0.16 and make the following edits:
./src/main.wasp
./src/queries.js
./src/util.js
Run
wasp start
and you should see the error:Explanation
Wasp bundles the server with Rollup, meaning that server code (and the user code it imports, e.g., operations) can use extensionless relative imports (e.g.,
import { sayHi } from './util'
).Wasp doesn't bundle the SDK (the
wasp
package), meaning that code in the SDK cannot use extensionless relative imports.Since Wasp copies all user code into the SDK (more precisely, into
wasp/ext-src
), it should mean that user code cannot use extensionless imports after all. But, as long as nothing references the offending code, no one will notice and everything will work.In practice, this means that user code can use extensionless relative imports as long as some other part of user code doesn't indirectly import the offending code from
wasp/ext-src
(e.g., by importingwasp/server/operations
).You could be working on your app for weeks, happily using extensionless relative imports. And then, one day, you import something from
wasp/server/operations
, which breaks your app in 100 places that have nothing to do with the change you just made (this is what happened to a user with OpenSaas)This behavior was also the root cause of this bug (albeit with slight differences): #2096 (comment)
Why isn't this caught during SDK build
At the time of writing, the SDK is built with TypeScript.
TypeScript can resolve extensionless files and doesn't alter import paths when outputting JS code, meaning that the error can only be caught in runtime.
Solution
The long term solution is figuring out how precisely how we want to treat and build the SDK.
The short-term solution is including the
wasp
package in the server's bundle (as we do for the client). @infomiho talks about it here: #2446The text was updated successfully, but these errors were encountered: