0

Edit This was marked as a duplicate of a question that has no useable answers. Here's how I addressed it:

var BASE = 'http://localhost:3001/'
export let {BASE_URL, LOGIN_URL, LOGIN_USER, LOGOUT_USER} = {
  BASE_URL: BASE,
  LOGIN_URL: BASE + 'sessions/create',
  SIGNUP_URL: BASE + 'users',
  LOGIN_USER: 'LOGIN_USER',
  LOGOUT_USER: 'LOGOUT_USER'
}

Original question I am exploring some React code from here. It has an npm script to browserify it which is:

"browserify --extension=.jsx --extension=.js src/app.jsx | uglifyjs > build/build.js"

However I cannot run this as it just freaks out on the ES6 code. I am not sure what setup the authors had. So I changed mine to:

"browserify --extension=.jsx --extension=.js src/app.jsx \
 -t [ babelify --presets [ es2015 react ] ] | uglifyjs > build/build.js"

This now builds "fine" except that code that is exported using exports default is undefined as in a file that contains:

var BASE_URL = 'http://localhost:3001/'
export default {
  BASE_URL: BASE_URL,
  LOGIN_URL: BASE_URL + 'sessions/create',
  SIGNUP_URL: BASE_URL + 'users',
  LOGIN_USER: 'LOGIN_USER',
  LOGOUT_USER: 'LOGOUT_USER'
}

In the file that imports it:

import { LOGIN_URL, SIGNUP_URL } from '../constants/LoginConstants'

The LOGIN_URL and SIGNUP_URL are undefined.

Any idea what is happening?

cyberwombat
  • 38,105
  • 35
  • 175
  • 251
  • I think export default take function and expression only. for object you need to make `export { }` – Pardeep Dhingra Dec 31 '15 at 06:35
  • `export { BASE_URL: BASE_URL, LOGIN_URL: BASE_URL + 'sessions/create' }` – Pardeep Dhingra Dec 31 '15 at 06:36
  • @PardeepDhingra yes I suspect that this code was written while still in draft mode. I am not sure where to find a clear spec though. Links like this https://people.mozilla.org/~jorendorff/es6-draft.html list `export default 42;` as valid so a bit unclear. – cyberwombat Dec 31 '15 at 06:50
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export – Pardeep Dhingra Dec 31 '15 at 07:39

0 Answers0