-1

This works

import config from './setup/config'
const {port} = config; 

This gives port as undefined

import config, {port} from './setup/config'
// config.port returns a number but port alone is undefined

This is also undefined

import {port} from './setup/config'
JasonAddFour
  • 153
  • 1
  • 1
  • 10

1 Answers1

2
const {port} = config; 

is a destructuring assignment. It "pulls" out the port property from the object in config.

import {port} from './setup/config'

imports the named export port from the module ./setup/config.

Your module probably doesn't have a named export port. Properties of an object that is exported as default export do not magically become named exports!

Make yourself more familiar with ES6 modules by reading

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143