0

I have a simple import statement:

import './dataMapper' as dataMap;

I am getting an error

Module build failed: SyntaxError: data.jsx: Unexpected token (1:22)

I can't seem to figure out why. If I just plain import without "as ...", it works.

According to at least this: http://www.sitepoint.com/understanding-es6-modules/

it is the correct syntax.

1 Answer 1

2

It's not the correct syntax (and it's not on the page you linked either). You'll want to have a look at http://www.2ality.com/2014/09/es6-modules-final.html for a good reference.

Your code should be

import dataMap from './dataMapper'; // to import the default

or

import * as dataMap from './dataMapper'; // to import the module object
Sign up to request clarification or add additional context in comments.

5 Comments

This is separate, I know this syntax. I am not talking about importing a particular exported value, but the entire module and then accessing exported values as properties. It is there on the linked page. Ctrl+F this to find it "You can also import the entire module as an object" (sans quotes)
Are you looking for import * as dataMap from './dataMapper';?
@SiamJi: Oh, I must have skipped that. import 'utility' as utils; is rubbish.
@loganfsmyth I guess that's the correct syntax then!
@SiamJi: That's what I'm saying, yes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.