Toby
Toby

Reputation: 13385

Export array as an es6 module

For some reason I'm unable to use an array exported as an es6 module:

export const choices = [
  ['first', 'First'],
  ['second', 'Second'],
  ['third', 'Third'],
]

Then:

import { choices } from './constants'
console.log(choices) // undefined

If I simply declare the const in the same file where I'm trying to use it, it works as expected.

Upvotes: 11

Views: 13178

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074295

Modules in browser contexts use relative URLs, including extension. So the import should be from './constants.js' rather than just from './constants'. (The latter would be fine on Node.js, though, with its currently-experimental modules support.)

Upvotes: 8

Related Questions