0

I am trying to use the variable in my env file but it's not working. but when I use the variable manually using the ENV file it will be working. what could be the issue

Here's my code

function handleSubmit (e) {
    e.preventDefault()
 emailjs.sendForm(process.env.REACT_APP_EMAILJS_SERVICE_ID,process.env.REACT_APP_EMAILJS_TEMPLATE_ID, form.current,process.env.REACT_APP_EMAILJS_PUBLIC_KEY)
    .then(function(response) {
      return setMessage(response.status)
    }, function(err) {
      console.log('FAILED...', err);
    });
  }

Here's my ENV file

REACT_APP_EMAILJS_SERVICE_ID='service_id'
REACT_APP_EMAILJS_TEMPLATE_ID='template_id'
REACT_APP_EMAILJS_PUBLIC_KEY="public_key"

1 Answer 1

1

Things you need to check

  1. .env files only take after a reboot in the CLI so you need to npm start or yarn start after updating any values
  2. Try saving the file .env.development which can be used as each Environment wise
  3. Try giving the value like this REACT_APP_EMAILJS_PUBLIC_KEY=public_key

As .env files contains key its best practice not to checkin to the source code so add this to gitignore.

. gitignore

.env.* //So all .env files are removed from the Git
Sign up to request clarification or add additional context in comments.

1 Comment

this is exactly what I did but am getting the service id and template id not found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.