Skip to content

Parse error when using dynamic imports #902

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

Closed
esturcke opened this issue Sep 7, 2017 · 2 comments
Closed

Parse error when using dynamic imports #902

esturcke opened this issue Sep 7, 2017 · 2 comments

Comments

@esturcke
Copy link

esturcke commented Sep 7, 2017

When using dynamic imports, I am seeing the following parse errors:

$ ./node_modules/.bin/documentation build src/index.js -f html -o docs                                                                                          10:00
SyntaxError: Unexpected token, expected { (8:8)
    at Parser.pp$5.raise (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:4454:13)
    at Parser.pp.unexpected (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:1761:8)
    at Parser.pp.expect (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:1749:33)
    at Parser.pp$1.parseImportSpecifiers (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:2898:8)
    at Parser.parseImportSpecifiers (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:6310:13)
    at Parser.pp$1.parseImport (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:2868:10)
    at Parser.pp$1.parseStatement (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:1884:49)
    at Parser.parseStatement (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:5910:22)
    at Parser.pp$1.parseIfStatement (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:2059:26)
    at Parser.pp$1.parseStatement (/Users/esturcke/projects/documentation-dynamic-import-bug/node_modules/babylon/lib/index.js:1846:19)

The source code for index.js is:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import registerServiceWorker from './registerServiceWorker';

const root = document.getElementById('root');
if (root)
  import("./App").then(({ default: App }) => ReactDOM.render(<App />, root));
registerServiceWorker();

I've created a repo with the code that is failing to parse.

Is there a workaround and is this something that could be supported?

  • What version of documentation.js are you using?: 5.3.0
  • How are you running documentation.js (on the CLI, Node.js API, Grunt, other?): CLI
@tmcw
Copy link
Member

tmcw commented Sep 7, 2017

Okay, this one turned out to be simpler to fix than expected! There's an option in the babylon parser (which we use to parse JavaScript to an AST) called dynamicImport that was not enabled. I can enable it and fix this issue in a patch release.

@esturcke
Copy link
Author

esturcke commented Sep 7, 2017

This is working great on my non-trivial project as well. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants