I'm getting this error when deploying my server to Railway
file:///app/.wasp/build/server/bundle/server.js:12
import cheerio from 'cheerio';
^^^^^^^^^^^^^^^^
SyntaxError: The requested module 'cheerio' does not provide an export named 'default'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:122:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:188:5)
ChatGPT told me to replace the following line:
import cheerio from 'cheerio';
to
import * as cheerio from 'cheerio';
Since it's not quite clear where to change this, do I have to check all of my files under server and do this replacement?
5 Replies
Hi @mb23. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the error message you're seeing when deploying to Railway, it appears you have an import statement that's causing issues with the ESM module system. The error indicates that 'cheerio' doesn't provide a default export, which is why the suggested fix is to use
import * as cheerio from 'cheerio'
instead.
The challenge is finding where this import statement exists in your codebase. Since the error is occurring in the bundled server file, it could be in any of your server-side code files.
You have a few options to address this:
1. Search your codebase: Look for all instances of import cheerio from 'cheerio'
in your server-side code and replace them with the correct import syntax.
2. Customize your Dockerfile: As mentioned in the knowledge sources, you can create a custom Dockerfile in your project root that patches the problematic file before deployment:
This approach is described as "quite a bit advanced" in the documentation, but it allows you to make specific changes to the built files before deployment Deploying Manually.
3. Fix and rebuild: After making the necessary changes to your source files, run wasp build
to rebuild your app, then redeploy using railway up
in the .wasp/build
directory as mentioned in the documentation Deploying Manually.
The error message itself isn't very descriptive about which specific file has the issue, which is a known problem with Wasp's error reporting. There's an open GitHub issue about improving error messages in the framework Improve error messages reported by the framework code.
If you're still having trouble locating the file, you might want to use a global search in your project for "cheerio" to find all instances of this import.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @mb23, 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?Where are you using
cheerio
in your project? Did you succeed in running your app locally?@miho @kapa.ai Seems like the issue happens locally as well. If I change it to "import * as cheerio from 'cheerio';", the issue changes to:
[ Server!] import cheerio__default from 'cheerio';
[ Server!] ^^^^^^^^^^^^^^^^
[ Server!] SyntaxError: The requested module 'cheerio' does not provide an export named 'default'
[ Server!] at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
[ Server!] at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
[ Server!] at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
[ Server!] at async loadESM (node:internal/process/esm_loader:28:7)
[ Server!] at async handleMainPromise (node:internal/modules/run_main:113:12)
Let me check the knowledge base for you again. One moment! :books:
----------------------
I see you're still encountering import issues with the cheerio package, but now the error is slightly different. This is a common issue with module imports in JavaScript/TypeScript, especially when dealing with packages that don't have a default export.
The new error shows that even after changing to
import * as cheerio from 'cheerio'
, there's still a reference to cheerio__default
somewhere in your code or in Wasp's generated code.
This is a known issue with import/export patterns in JavaScript modules. Based on the knowledge sources, there are a few things to consider:
1. Wasp has had discussions about default vs. named exports, with some contributors advocating for named exports over default exports due to various issues like the one you're experiencing Syntax considerations: Default and named exports.
2. The error message you're seeing is one of those that the Wasp team acknowledges could be improved to be more helpful Improve error messages reported by the framework code.
To fix this issue, you might need to:
1. Find all instances where cheerio is imported in your codebase
2. Check if there are any transpiled files in the .wasp
directory that might be using cheerio
3. Try using a different import pattern that works with cheerio's export structure
If you're using a recent version of Wasp (0.12.x), you might also try running:
This approach has helped others with similar import-related issues, as it rebuilds the .wasp
folder and reinstalls dependencies Discord support thread.
If the issue persists, you might need to look at how cheerio is being used in your codebase and consider alternative approaches or packages that are more compatible with ESM modules.
Would you be able to share which version of Wasp you're using and how you're using cheerio in your application? That might help narrow down the solution.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @mb23, 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?What version of cheerio do you have in package.json? Something similar happened to me.
Try to replace:
by
import { load } from 'cheerio';