Skip to content

Parse error (unexpected token) on dynamic import #1149

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
alexgurr opened this issue Oct 10, 2018 · 10 comments · Fixed by #1205
Closed

Parse error (unexpected token) on dynamic import #1149

alexgurr opened this issue Oct 10, 2018 · 10 comments · Fixed by #1205

Comments

@alexgurr
Copy link

If you're reporting a bug, please include input code, output documentation,
a description of what you expected to happen, and what happened instead.

  • What version of documentation.js are you using?: 9.0.0 ALPHA 0
  • How are you running documentation.js (on the CLI, Node.js API, Grunt, other?): CLI
export default class Icon extends React.Component<IconProps, IconState> {
  static defaultProps: Object;

  constructor(props: IconProps) {
   ...
   import(`../../../assets/icons/${props.name}.svg`)
      .then(url => this.setState({ icon: url }))
      .catch(() => {});
  }

When I comment this 'import' statement out, documentation.js runs fine. When I leave it in I get: "Icon.js: Unexpected token (52:10)".

I saw this was fixed in a PR last year but seems to be a problem for me?

@tmcw
Copy link
Member

tmcw commented Oct 10, 2018

Yep, per this comment the dependencies that we relied on with Babel 6 compatibility are not yet available for Babel 7, so the 9.0.0-alpha.0 release temporarily drops dynamic import() support until those dependencies are updated or a fix is contributed.

@lensbart
Copy link

@tmcw maybe @babel/plugin-syntax-dynamic-import could be a suitable replacement?

@kopax
Copy link

kopax commented Feb 8, 2019

[tc39/proposal-dynamic-import] chunk synthax with import() such as react-loadable not working

Any update on this? Is there a way to exclude those file that use import() while waiting for a documentationjs fix ? We use massively those for application chunking:

We are having in our source files such as:

import Loadable from 'react-loadable';

export default Loadable({
  loader: () => import('./index'),
});

Documentation fail with:

Error: Parsing file /home/dka/workspace/module.kopaxgroup.com/kopaxgroup-api/um-users/src/containers/AuthoritiesEdit/Loadable.js: Unexpected token (14:11)
    at Deps.parseDeps (/home/dka/workspace/module.kopaxgroup.com/kopaxgroup-api/um-users/node_modules/module-deps-sortable/index.js:515:28)
    at fromSource (/home/dka/workspace/module.kopaxgroup.com/kopaxgroup-api/um-users/node_modules/module-deps-sortable/index.js:450:44)
    at /home/dka/workspace/module.kopaxgroup.com/kopaxgroup-api/um-users/node_modules/module-deps-sortable/index.js:444:17
    at ConcatStream.<anonymous> (/home/dka/workspace/module.kopaxgroup.com/kopaxgroup-api/um-users/node_modules/module-deps-sortable/node_modules/concat-stream/index.js:36:43)
    at ConcatStream.emit (events.js:202:15)
    at finishMaybe (/home/dka/workspace/module.kopaxgroup.com/kopaxgroup-api/um-users/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:475:14)
    at endWritable (/home/dka/workspace/module.kopaxgroup.com/kopaxgroup-api/um-users/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:485:3)
    at ConcatStream.Writable.end (/home/dka/workspace/module.kopaxgroup.com/kopaxgroup-api/um-users/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:455:41)
    at DuplexWrapper.onend (/home/dka/workspace/module.kopaxgroup.com/kopaxgroup-api/um-users/node_modules/readable-stream/lib/_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:285:13)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @kopaxgroup-api/um-users@0.0.0-development jsdoc-documentation: `jsdoc-documentation "src/**/*.js" "docs/js/jsdoc.md"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @kopaxgroup-api/um-users@0.0.0-development jsdoc-documentation script.

Version: 9.1.1

I bet it's the dynamic import. that's only stage 3 https://github.com/tc39/proposal-dynamic-import/#import

Is there a way to use this syntax with documentationjs OR exclude all files named Loadable.js ?

@dbnapp
Copy link

dbnapp commented Mar 8, 2019

This issue is pretty bad, would like if there was a way to ignore files, that'd be a good temp fix. No reason for one file to make the entire documentation fail.

@kopax
Copy link

kopax commented Mar 8, 2019

I agree. I don't know how to fix it otherwise it would already be. All our documentation in every small npm package we do are down as soon as we use one import() statement. We use import statement for all our backend page features. Anyway you can help here @dbnapp ?

@kopax
Copy link

kopax commented Apr 1, 2019

I have tried and #1205 did not solve #1149, without change I have this:

Error: Parsing file /home/dka/workspace/github.com/yeutech-lab/react-intl-polyfill/src/IntlPolyfill.js: Unexpected token (66:23)
    at Deps.parseDeps (/home/dka/workspace/github.com/yeutech-lab/react-intl-polyfill/node_modules/module-deps-sortable/index.js:515:28)
    at fromSource (/home/dka/workspace/github.com/yeutech-lab/react-intl-polyfill/node_modules/module-deps-sortable/index.js:450:44)
    at /home/dka/workspace/github.com/yeutech-lab/react-intl-polyfill/node_modules/module-deps-sortable/index.js:444:17

Using --babel=./babel.config.js I have

Unknown argument: babel

@amidf
Copy link

amidf commented Apr 10, 2019

@kopax did you solve the problem with these terrible dynamic imports? I just have the same problem. If you did, please, help me.

@kopax
Copy link

kopax commented Apr 11, 2019

No, I did not. I end up with this comment: #1205 (comment)

@amidf
Copy link

amidf commented Apr 11, 2019

Okay, it's sad.

@kopax
Copy link

kopax commented Apr 11, 2019

@amidf It is not sad, look #1205 (comment)

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

Successfully merging a pull request may close this issue.

6 participants