Skip to content

Dynamic routes in data loader: SyntaxError: FileAttachment requires a single literal string argument (4:14) #1703

Answered by Fil
spandl asked this question in Q&A
Discussion options

You must be logged in to vote

The difference is static analysis. The Observable markdown parser can detect the former, because it has a unique shape that does not require to run the code to know what the values are.

But for the latter, the only way to know the value of the variable is to run the code—and this is out of bounds (and sometimes squarely impossible, say if your code depends on a random number or a date).

In other words (and that may be a bit of a stretch of a metaphor), we can "compile" the page, but not "execute" it. (At the end of the process we need to build static files.)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@spandl
Comment options

Answer selected by spandl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants