I just accidentally atetmpted to roc run on an exectutable non-.roc file and got the following error.
$ roc run examples/csv-movies
── MISSING HEADER in examples/csv-movies ───────────────────────────────────────
I am expecting a header, but the file is not UTF-8 encoded.
I am expecting a module keyword next, one of interface, app, package
or platform.%
Should the cli check for the .roc extension and return a more helpful error? or is it expected that roc scripts/apps may use alternative file extensions?
They may have no extension if we want roc to be used for scripting
But probably just that and .roc is good
Why would a roc file have no extension?
Cause when making a script it is nice to just write app-name or ./app-name. For example a lot of shell scripts omit the extension instead of app-name.sh, it is just app-name
or sometimes you have a third-party tool which runs a hardcoded executable name (e.g. one it expects to be on your PATH) and you want to have it run your script
Ok, thanks for explaining that. I'll just leave this as is for now then.
I think we should totally give an error for anything that is a .not-roc
So either no extension or specifically just .roc
Ok, I'll make an issue
https://github.com/roc-lang/roc/issues/6418
If the filename has no extension, we could require the first line to start with#! and contain roc somewhere?
Yeah, that's a good idea
Are we sure someone won't legitimately rename their interpreter?
we can certainly enforce that the first line for an extensionless file starts with #!, though I'm not sure that's necessary either?
Do bourne shells enforce extensions or having a shebang line? sh doesn't parse the whole file before executing, but rather just parses the next statement (or if it's something like a loop or conditional, just parses until the done or fi before executing that block of code. Granted, that's somewhat of a historical feature of shells of that kind, because you could have an executive #!/bin/sh file that checks, for example, if unzip is installed, and if not, installs it, and then runs unzip on the same file.
Since Roc parses the whole file before any code will get executed, the chance of an arbitrary non-Roc file being valid Roc code is pretty low.
I feel like this is better handled via clear errors rather than up-front enforcement: when you attempt to run, and there are any syntax errors, check if the extension is .roc or there was a shebang line containing roc, and if not, crash with a message like:
You attempted to run this file with Roc, but it does not appear to be a
*.rocor#!/.../rocfile.If this is actually a Roc file, please run with:
roc run --all-errors relpath/to/this-file
If instead, the file does not have syntax errors, but does have other errors (like a type error), then treat it as a Roc file despite having an unusual file extension or shebang line.
Last updated: Jun 16 2026 at 16:19 UTC