Title: How to handle javascript with import statements
Tags: angular;webpack
Question: I Updated to RC6 today an got SyntaxError: Unexpected token import from @angular/core/src/reflection/reflection.js. Upon inspection many other .js files in the @angular/core npm package have import statements. Why do compiled .js files have import statements and how do I configure webpack to handle them?
Comment: `import` in vendor.ts like https://github.com/angular/angular2-seed/blob/master/src/vendor.browser.ts

Comment: I think the root of the issue is that webpack is ignoring package.json's `"main": "bundles/core.umd.js"` and using index.js

Comment: https://gist.github.com/gatimus/8d880cab3d9f2ac08475dfb701ae9d17

Comment: Thank you @Mario Tacke, I found out on another site that I should be using `@angular/core/bundles/core.umd.js` not `@angular/core/src/reflection/reflection.js` as it is a ESM (ES6 module) file.

Comment: How are you including angular2 in your project? (require, import, head, etc)

Comment: Show us your `webpack.config.js`. Maybe you are missing a loader.

Comment: Looks like its missing a loader. Have you tried babel for the js file its trying to load? `import` statements need to be transpiled before they can execute on the client.


Here is another answer: I'm answering this to close the question. My question didn't really apply because I should be using @angular/core/bundles/core.umd.js not @angular/core/src/reflection/reflection.js as it is a ESM (ES6 module) file. For those who want to know the answer, javascript files with import statements should be used in ES6 environments and not currently in the browser unless transpiled with bable (credit @Mario Tacke)

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 7, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:09/07/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<angular><webpack>', 'Title': 'How to handle javascript with import statements', 'ViewCount': 53, 'id': 39377963, 'user_AboutMe': '', 'user_AccountId': 8919042.0, 'user_DisplayName': 'William Lohan', 'user_Reputation': 2517.0, 'user_Views': 312.0, 'user_id': 6656422.0}}