How to map gf to files or return <cr> otherwise?

I slready have this:

vim.keymap.set("n", "<cr>", function()
  local path = vim.fn.expand("<cfile>")
  local ok, result = pcall(vim.cmd, 'gf ' .. path)
  if not ok then
    return "<cr>"
  end
  -- If 'gf' succeeded, return an empty string to prevent further actions
  return ""
end, { expr = true })

but to files like: require(“core.utils”) it does not work