-
Notifications
You must be signed in to change notification settings - Fork 734
Description
Description
When running spacetime dev in a directory with spacetime.json but without a properly initialized TypeScript project, the error messages are confusing and don't guide users to the root cause.
Steps to Reproduce
- Create a directory with
spacetime.jsonandspacetime.local.json:
// spacetime.json
{
"server": "maincloud"
}
// spacetime.local.json
{
"database": "test-db"
}-
Have a
package.jsonpresent (either symlinked or for a different project) that doesn't include TypeScript as a dependency -
Do NOT have a
tsconfig.jsonfile -
Run
spacetime dev <database-name>
Actual Behavior
The CLI outputs:
Found existing SpacetimeDB project.
...
Building...
tsc not found in node_modules. Make sure you have the `typescript` package as a dev-dependency and that your dependencies are installed.
Error: Failed to build project
Caused by:
Something went wrong inside rolldown, please report this problem at https://github.com/rolldown/rolldown/issues.
Tsconfig not found /home/user/tsconfig.json
Caused by:
Failed to resolve `tsconfig` option: /home/user/tsconfig.json
Expected Behavior
The CLI should:
-
Validate project structure - Don't just check for
spacetime.jsonto determine if a project exists. Validate that the project is properly initialized with:- Correct
package.jsonwith required dependencies tsconfig.jsonfor TypeScript projects- The
spacetimedb/directory with module code
- Correct
-
Provide actionable error messages - Instead of a cryptic rolldown error, show:
Error: TypeScript project not properly initialized Missing or invalid files: - tsconfig.json not found - TypeScript dependency not installed - spacetimedb/ module directory not found To fix this, run: spacetime init --lang typescript <project-name> -
Detect incomplete initialization - When
spacetime.jsonexists but other required files don't, warn the user:Warning: Found spacetime.json but project appears incomplete. Did you mean to run 'spacetime init --lang typescript'?
Environment
- SpacetimeDB CLI version: 2.0.1
- OS: Linux
- Node.js version: v22.20.0
Additional Context
This issue affects developer experience, especially for new users trying to set up SpacetimeDB projects. The current error message:
- Incorrectly states "Found existing SpacetimeDB project" when the project isn't properly set up
- Points to a rolldown GitHub issues page instead of helping users fix their setup
- Doesn't mention that
spacetime initshould be used to properly initialize a project
Suggested Fix
Add validation in the CLI before attempting to build:
// Pseudocode
fn validate_typescript_project(project_path: &Path) -> Result<(), Error> {
if !project_path.join("tsconfig.json").exists() {
return Err(Error::MissingTsConfig {
suggestion: "Run 'spacetime init --lang typescript' to create a new project"
});
}
if !typescript_installed(project_path) {
return Err(Error::MissingTypeScript {
suggestion: "Install TypeScript with: npm install --save-dev typescript"
});
}
if !project_path.join("spacetimedb").exists() {
return Err(Error::MissingModuleDirectory {
suggestion: "Create a spacetimedb/ directory with your server module code"
});
}
Ok(())
}Labels
- bug
- developer-experience
- cli
- typescript