Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error thrown on ES2015 Loader import() call #37

Closed
oliverturner opened this issue Jan 10, 2017 · 4 comments
Closed

Error thrown on ES2015 Loader import() call #37

oliverturner opened this issue Jan 10, 2017 · 4 comments
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@oliverturner
Copy link

oliverturner commented Jan 10, 2017

In files using ES2015 Loader spec (e.g. bundle splitting with webpack@2.2.0-rc.3), import(...) throws with SyntaxError: Unexpected token.

This is true whether using the flow parser or babylon

Sample code:

import React from 'react'
import idbKeyval from 'idb-keyval'

import Shell from './components/app-shell'

class AppShell extends React.Component {
  constructor () {
    super()

    this.state = {app: <Shell />}
  }

  componentWillMount () {
    Promise.all([
      idbKeyval.get('store'),
      import('./root')
    ])
    .then(
      ([data, module]) => { this.setState({app: <module.default initialData={data} /> })}, 
      (err) => {console.log(err)}
    )
    .catch((err) => {
      console.log('Chunk loading failed', err)
    })
  }

  render () {
    return this.state.app
  }
}

export default AppShell
@hzoo
Copy link
Contributor

hzoo commented Jan 10, 2017

this is because the babylon plugin dynamicImport isn't used (also on a fork of babylon atm since we haven't released)

I was about to do this but its a good beginner-friendly issue.

@oliverturner
Copy link
Author

@hzoo Just saw that myself... happy to close if it's a known quantity.

@hzoo
Copy link
Contributor

hzoo commented Jan 10, 2017

Can close via #51

@oliverturner
Copy link
Author

Closing per this recommendation

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 8, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

2 participants