W
Wasp4mo ago
Conspyre

server side imports of the form "./foo" used to work and now fail

Example: import { taskCache } from './config'; This was working for many versions. I've created a new branch, added a bunch of new code which appears to have caused a new issue with this import style. Now there are dozens of compile errors in the old code. ALL imports of this nature are failing. To make them compile again, I seem to have to do a pattern like: import { taskCache } from "../server/config.js" What could cause this behavior - and why do I need to make this change across a lot of imports which used to just work? I have not updated wasp.
4 Replies
kapa.ai
kapa.ai4mo ago
Hi @Conspyre. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- This issue might be related to the restructuring changes in Wasp v0.12. Before this version, files had to be in src/client or src/server directories, which made it clear if they were client or server files. Also, imports in main.wasp started with either @client or @server, and there were checks that would prevent them from importing a client file where a server file was expected, and vice versa. However, with the new restructuring in Wasp v0.12, everything is in src/ and users can mix client and server files as they like. This means that the import paths have to be adjusted accordingly. For example, if you previously had something like import { taskCache } from './config';, you might now need to change it to import { taskCache } from '../server/config.js'; or similar, depending on your project structure. There are also ongoing discussions about improving the import system in Wasp, as seen in these GitHub issues: Fix inconsistent import extensions in both .wasp file and in JS files (https://github.com/wasp-lang/wasp/issues/1363) and Improve error messages reported by the framework code (https://github.com/wasp-lang/wasp/issues/1664). If you recently migrated to Wasp v0.12, you might want to check the migration guide (https://wasp-lang.dev/docs/migrate-from-0-11-to-0-12#migrating-your-project-to-the-new-structure) for more details on how to adjust your import paths. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Conspyre, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Conspyre
ConspyreOP4mo ago
@kapa.ai I have been on 0.14 the entire time. The branch "master" is compiling just fine. The branch "new" is failing, but it is not failing in the new code, it is failing in the code which was not modified. Very strange!
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- That does sound strange! If you're sure that the code causing the issue hasn't been modified, it might be worth considering a few things: 1. Dependencies: Have there been any changes in the dependencies that might affect the import paths? Sometimes, updating a package can cause unexpected behavior in other parts of your code. 2. Environment: Are there any differences in the environment where the two branches are being compiled? This could include things like Node.js version, operating system, etc. 3. Code Structure: Even if the problematic code hasn't been modified, changes in other parts of your codebase (like moving files or directories) could affect the import paths. 4. Caching: Sometimes, old cache can cause unexpected issues. Try clearing your build cache and recompiling your project. If none of these seem to be the issue, it might be helpful to create a minimal reproduction of the problem and open an issue (https://github.com/wasp-lang/wasp/issues) on the Wasp GitHub repository. The Wasp team and community can then help you investigate the problem further. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Conspyre, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho4mo ago
Ok, if I understood thing correctly, this is the case: 1. You are using Wasp 0.14.0 from the start and you didn't update the Wasp version 2. You have some code on the master branch which works for you 3. You have some code on new that fails? 4. The import that fails is this:
import { taskCache } from './config';
import { taskCache } from './config';
My questions: 1. Where is this import happening? On the client? 2. Where do you see the errors: the terminal or browser console? 3. What do you have in the config.ts file? Are you using env vars in that file?
Want results from more Discord servers?
Add your server