Search code examples
metaprogrammingnim-lang

Open file at compile-time [JS backend]


I'm trying open file in macro, but I got exception:

template/generic instantiation of `some` from here
Error: cannot 'importc' variable at compile time; fopen

My Nim code:

import macros


macro some(): untyped =
  var f = open("some.txt")
  echo f.readAll()
  f.close()

some()

to compile:

nim js file

Solution

  • use

    staticRead("some.txt")