title: Extra quote marks in Node JSON.stringify
body: <p>I have a module that creates and exports a config object. When running in a browser environment, its string values <em>must</em> be JSON.stringified. Otherwise, they are interpreted as bare identifiers.</p>
  
  <p>In node, JSON.stringify seems to add an extraneous set of double quotes.</p>
  
  <p>What solution would work in both browser and node?</p>
  
  <p>Most of the node modules I've checked out, searching for JSON.stringify deal with String representations/translations of complex objects. </p>
  
  <h2>works in browser + webpack 2.2.4, fails in node:</h2>
  
  <pre><code>module.exports = {
      url: JSON.stringify(process.env.SOME_URL),
      // in node, resolves to '"https://..."'
      headers: {
          Authorization: JSON.stringify(basicAuthString),
          // in node, resolves to '"Basic ...="'
          'Content-Type': JSON.stringify('application/json'),
      }
  };
  </code></pre>
  
  <h2>works in node, fails in browser + webpack 2.2.4:</h2>
  
  <pre><code>module.exports = {
      url: process.env.SOME_URL,
      // in node, resolves to bare https://...
      // Uncaught SyntaxError: Unexpected token :
      headers: {
          Authorization: basicAuthString,
          // in browser, resolves to bare Basic ...=
          // actions.js:15 Uncaught SyntaxError: Unexpected identifier
          'Content-Type': JSON.stringify('application/json'),
      }
  };
  </code></pre>
  
  <p>The <code>process.env</code> values, in the case of webpack, are captured at build time, using this approach: <a href="https://github.com/AngularClass/angular2-webpack-starter/wiki/How-to-pass-environment-variables" rel="nofollow noreferrer">https://github.com/AngularClass/angular2-webpack-starter/wiki/How-to-pass-environment-variables</a></p>
  
  <h2>Update: Workaround and remaining question</h2>
  
  <ol>
  <li>What is the <strong>root cause</strong> of the issue?
  
  <ul>
  <li>the library code  </li>
  <li>webpack 2x that builds library user projects</li>
  <li>Babel 6.24.1, used to build the library</li>
  </ul></li>
  </ol>
  
  <p>This workaround just checks for repeated quotes at beginning and end. It works in both environments.</p>
  
  <pre><code>const str = (s) =&gt; {
      let ret = JSON.stringify(s);
      if (ret.indexOf('""') === 0) {
        ret = ret.slice(1);
      }
      if (ret[ret.length - 2] === '"') {
        ret = ret.slice(0, -1 + ret.length);
      }
      return ret;
  };
  
  module.exports = { foo: str('bar') };
  </code></pre>