Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Direct export throws SyntaxError #17

Closed
msuntharesan opened this issue Dec 19, 2016 · 23 comments
Closed

Direct export throws SyntaxError #17

msuntharesan opened this issue Dec 19, 2016 · 23 comments
Assignees

Comments

@msuntharesan
Copy link
Contributor

when you export from another module like export App from './App' throws SyntaxError

SyntaxError: Unexpected token (1:7)
    at Parser.pp$4.raise (/home/mohan500/project/git/github.com/react-example/node_modules/acorn/dist/acorn.js:2431:15)
    at Parser.pp.unexpected (/home/mohan500/project/git/github.com/react-example/node_modules/acorn/dist/acorn.js:616:10)
    at Parser.pp.expect (/home/mohan500/project/git/github.com/react-example/node_modules/acorn/dist/acorn.js:610:28)
    at Parser.pp$1.parseExportSpecifiers (/home/mohan500/project/git/github.com/react-example/node_modules/acorn/dist/acorn.js:1324:10)
    at Parser.pp$1.parseExport (/home/mohan500/project/git/github.com/react-example/node_modules/acorn/dist/acorn.js:1260:30)
    at Parser.pp$1.parseStatement (/home/mohan500/project/git/github.com/react-example/node_modules/acorn/dist/acorn.js:754:71)
    at Parser.parseStatement (/home/mohan500/project/git/github.com/react-example/node_modules/acorn-es7/acorn-es7.js:72:28)
    at Parser.pp$1.parseTopLevel (/home/mohan500/project/git/github.com/react-example/node_modules/acorn/dist/acorn.js:658:25)
    at Parser.parse (/home/mohan500/project/git/github.com/react-example/node_modules/acorn/dist/acorn.js:528:17)
    at Object.parse (/home/mohan500/project/git/github.com/react-example/node_modules/acorn/dist/acorn.js:3309:39)

Fork

@nchanged
Copy link
Contributor

nchanged commented Dec 19, 2016

Okay, are you sure that App has default exports? Cuz if it does not, you will get this error

Even my vscode complains on the syntax above.
try

export { App } from './App';

@msuntharesan
Copy link
Contributor Author

Yes it does. see fork

@nchanged
Copy link
Contributor

It says Declaration or statement expected

@msuntharesan
Copy link
Contributor Author

Sorry about that. Fixed the import. Still same error

@nchanged
Copy link
Contributor

If acorn complains that means that you have a syntax error

@devmondo
Copy link
Member

@VanthiyaThevan is it possible that you are using some feature that needs some babel plugin, or you are just using the original repo code?

@eisisig
Copy link

eisisig commented Dec 19, 2016

I'm actually getting this error (Unexpected token) and error reporting from acorn really doesn't help.

@devmondo
Copy link
Member

@VanthiyaThevan i checked the project,

first there is syntax error here react example
cons should be const
also
export App from './App';
should be
export { App } from './App';

after i fixed those, build is passing fine, hope this helps

@nchanged
Copy link
Contributor

Also please, make sure you references make sense
https://github.com/vanthiyathevan/react-example/blob/master/src/App/index.js#L1
You don't have App.js file in that folder.

@msuntharesan
Copy link
Contributor Author

the difference to this working vs the the error
this throws error

export App from './App'

This compiles as expected.

import App from './App'
export { App };

@devmondo It is possible. I've switched to using presets latest, stage-0, and react and explicitly added transform-export-extensions. Still same acorn error.

@devmondo
Copy link
Member

devmondo commented Dec 19, 2016

@VanthiyaThevan thanks for update,

can you try this export {App} from './App' directly without import statement.

@msuntharesan
Copy link
Contributor Author

@devmondo
Hmm interesting. export {App} from './App' works. But given the ./App is default export, Shouldn't export App from './App' be working?

@nchanged
Copy link
Contributor

export App from './App' is not a valid syntax.
Please. read up here

@msuntharesan
Copy link
Contributor Author

I see now. the syntax I am using are part of proposal

and stage 1 supported by babel and not by acorn.
see the astexplorer.net

@nchanged
Copy link
Contributor

nchanged commented Dec 19, 2016

I see. I think we can use babel AST as an alternative.
Required:

  • A way to bypass acorn parse and use AST provided by other sources. (for example by babel-plugin)

@nchanged
Copy link
Contributor

1.3.13 has it fixed. stage-0 does not spit an error, however, is not giving me expected code back.
It transpiles it as "undefined". So it must be related to that plugin. Nonetheless, all questions to babel.

@msuntharesan
Copy link
Contributor Author

Thanks for the quick response. But if I specify my own test without limit2project this reverts to using only acron AST only because of This

@nchanged
Copy link
Contributor

Sorry, my bad. FIxed in v1.3.15

@devmondo
Copy link
Member

i can confirm that Error reporting in v1.3.16 is awesome now!!!

@nchanged
Copy link
Contributor

Nice! @devmondo Thanks,
Let's wait for @VanthiyaThevan to confirm that BabelPlugin is now using babel AST instead of acorn.

@msuntharesan
Copy link
Contributor Author

Thanks. This works. Yes the error message is very cool. Will try it on a real project and let you know.
The undefined is because of babel transpiling.
Although when export is pointing to a non existing file, The transpiling goes through without errors. May be it should warn the file doesn't exist?

@nchanged
Copy link
Contributor

Hi!
Thanks!
Certainly a warning can be optional. But in essence, a user might require a file that's not in a bundle. And get it via dynamic imports. So this has to be though through.

Thanks again for submitting this issue, it led to an amazing improvement on BabelPlugin and the core itself.

Cheers.

@msuntharesan
Copy link
Contributor Author

Thanks. I'm going to try this on a fairly large project.

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

No branches or pull requests

4 participants