Nuxt.js: Dollar sign ($) in .env value converted to 'undefined' in $config

Created on 4 Sep 2020  路  4Comments  路  Source: nuxt/nuxt.js

Versions

  • nuxt: v2.14.4
  • node: v12.14.1

Reproduction


Additional Details



Steps to reproduce

  • In a .env file, add an entry that contains a $ in the value:
MY_PASSWORD=bug$
FOO=$bug
  • At the top of your nuxt.config.js file, import dotenv:
require('dotenv').config();
  • In nuxt.config.js, set a privateRuntimeConfig attribute, using the .env value:
privateRuntimeConfig: {
  myPassword: process.env.MY_PASSWORD,
  foo: process.env.FOO
}

What is Expected?

context.$config.myPassword should equal 'bug$'
context.$config.foo should equal '$bug'

What is actually happening?

context.$config.myPassword equals 'bugundefined'
context.$config.foo equals undefined (NOTE: not a string! This is the javascript value undefined)

This means that any value in .env that contains a '$' character wont work in $config, which seems highly likely given that you're probably keeping passwords, api keys, etc in .env

bug-report stale

Most helpful comment

All 4 comments

Workaround:
Escaping the '$' in .env with a double backslash will produce the expected result in $config

MY_PASSWORD=bug\\$
FOO=\\$bug

Hi @gbruins-notours It should be fixed by #8013 (you can try with using nuxt-edge package). But escaping $ is best workaround.

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vadimsg picture vadimsg  路  3Comments

gary149 picture gary149  路  3Comments

surmon-china picture surmon-china  路  3Comments

vadimsg picture vadimsg  路  3Comments

bimohxh picture bimohxh  路  3Comments