Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS Build Error - Please verify your .env file is correctly formatted. #522

Open
akiladevinda opened this issue Nov 11, 2020 · 7 comments
Open

Comments

@akiladevinda
Copy link

I git this error after installing pod and run from xcode

Invalid entry in .env file. Please verify your .env file is correctly formatted.

@shllg
Copy link

shllg commented Nov 11, 2020

One issue at my setup has been, that ios/ReactNativeConfig/ReadDotEnv.rb doesn't accept anything else except key-value pairs. In my case, I had empty lines and comments in my .env file.

On quick solution is to remove those.

I patched the part of ios/ReactNativeConfig/ReadDotEnv.rb by replacing lines 41-52 with:

raw.split("\n").each_with_index.inject({}) do |h, line_pair|
  line, index = line_pair

  next h if line.nil? || line == '' || line == ' '
  next h unless line.match(comment_line_pattern).nil?

  m = line.match(dotenv_pattern)

  if m.nil?
    abort("Invalid entry in .env file. Please verify your .env file is correctly formatted (line: #{index + 1}, value: #{line}).")
  end

  key = m[:key]
  # Ensure string (in case of empty value) and escape any quotes present in the value.
  val = m[:val].to_s.gsub('"', '\"')
  h.merge(key => val)
end

It ignores comments and empty lines.

@ManhVuTien
Copy link

One issue at my setup has been, that ios/ReactNativeConfig/ReadDotEnv.rb doesn't accept anything else except key-value pairs. In my case, I had empty lines and comments in my .env file.

On quick solution is to remove those.

I patched the part of ios/ReactNativeConfig/ReadDotEnv.rb by replacing lines 41-52 with:

raw.split("\n").each_with_index.inject({}) do |h, line_pair|
  line, index = line_pair

  next h if line.nil? || line == '' || line == ' '
  next h unless line.match(comment_line_pattern).nil?

  m = line.match(dotenv_pattern)

  if m.nil?
    abort("Invalid entry in .env file. Please verify your .env file is correctly formatted (line: #{index + 1}, value: #{line}).")
  end

  key = m[:key]
  # Ensure string (in case of empty value) and escape any quotes present in the value.
  val = m[:val].to_s.gsub('"', '\"')
  h.merge(key => val)
end

It ignores comments and empty lines.

So can you show me comment_line_pattern

@greghaygood
Copy link
Contributor

I also have comments in my .env files, so I updated it with this (same as @shllg's, but without the separate comment_line_pattern var):

raw.split("\n").each_with_index.inject({}) do |h, line_pair|
  line, index = line_pair

  next h if line.nil? || line == '' || line == ' '
  next h if line.match(/^\s*#/)

  m = line.match(dotenv_pattern)

  if m.nil?
    abort("Invalid entry in .env file. Please verify your .env file is correctly formatted (line: #{index + 1}, value: #{line}).")
  end

  key = m[:key]
  # Ensure string (in case of empty value) and escape any quotes present in the value.
  val = m[:val].to_s.gsub('"', '\"')
  h.merge(key => val)
end

@josevalb
Copy link

josevalb commented Dec 4, 2020

I have the same issue. never happened before. remove and pod install again. my .env file does not have invalid entries. no clue what's happening

@wojo1206
Copy link

wojo1206 commented Dec 4, 2020

1.4.0 is free of this error. Downgrade to 1.4.0

@sharmapr25
Copy link

sharmapr25 commented Dec 22, 2020

@josevalb Even .env file is valid still it won't take other .env files apart from .env.dev. I have fixed this issue already raised a pr. #539
Meanwhile, you can edit your package.json like this:
"react-native-config": "git+https://github.com/CoffeeBeansLabs/react-native-config.git"
it will work fine 👍

@STonkoshkur
Copy link

Looks like it was fixed in v 1.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants