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

SyntaxError: Unexpected token 'export' #488

Closed
ali-heidari opened this issue Jul 22, 2020 · 20 comments
Closed

SyntaxError: Unexpected token 'export' #488

ali-heidari opened this issue Jul 22, 2020 · 20 comments

Comments

@ali-heidari
Copy link

Describe the bug

It seems there is a problem with exporting different versions inside of uuid. My project is using uuidv4 which is using uuid.

To Reproduce

Steps to reproduce the behavior:

  1. Install 'uuidv4'
  2. Run project (commonJs style)
  3. See error

Expected behavior

Expected to run without problem.

Runtime

  • OS: Win10
  • Runtime: Node.js
  • Runtime Version: 14.3.0

Additional context

You can see the error here:

...\node_modules\uuidv4\node_modules\uuid\dist\esm-browser\index.js:1
export { default as v1 } from './v1.js';
^^^^^^

SyntaxError: Unexpected token 'export'
@TrySound
Copy link
Member

This point is not clear. Is it node project or some bundler, which bundler?

Run project (commonJs style)

@ali-heidari
Copy link
Author

It is node project... I guess it happens because of my node written in commonJs and uuid is es6!

@TrySound
Copy link
Member

Nope. UUID is distributed as commonjs by default.
https://unpkg.com/browse/uuid@8.2.0/dist/index.js

How do you import uuid? And provide please minimal reproduction.

@ali-heidari
Copy link
Author

ali-heidari commented Jul 23, 2020

But my console shows an error

node_modules\uuidv4\node_modules\uuid\dist\esm-browser\index.js:1
    export { default as v1 } from './v1.js';
    ^^^^^^

    SyntaxError: Unexpected token 'export'
        at compileFunction (<anonymous>)
        at wrapSafe (internal/modules/cjs/loader.js:1116:16)
        at Module._compile (internal/modules/cjs/loader.js:1164:27)

which pointed to this file:

export { default as v1 } from './v1.js';
export { default as v3 } from './v3.js';
export { default as v4 } from './v4.js';
export { default as v5 } from './v5.js';

What am i missing here?
what is the root of problem ? uuidv4? uuid? esm-browser????

@TrySound
Copy link
Member

Show how do you import uuid, give us a reproduction.

@ali-heidari
Copy link
Author

This is how i import:

const { uuid } = require('uuidv4');

@TrySound
Copy link
Member

This package?
https://www.npmjs.com/package/uuidv4

@TrySound
Copy link
Member

The wrong one. Please read documentation.

@TrySound
Copy link
Member

I see. This package is the dependency of your one. Could you switch to using uuid package directly?

@ctavan
Copy link
Member

ctavan commented Jul 27, 2020

Closing since this seems to be related to a reverse dependency of this package. Please open a bug report in the appropriate issue tracker if the problem persists: https://github.com/thenativeweb/uuidv4/

@riccardoNovaglia
Copy link

riccardoNovaglia commented Aug 5, 2020

Hey folks, I think this still might be an issue, getting exactly the same problem, importing uuid directly.

Made a repo here to show the problem.

Versions:

➜  tmp git:(master) node --version
v13.2.0
➜  tmp git:(master) npm --version
6.14.7

Hope it helps

@ctavan
Copy link
Member

ctavan commented Aug 5, 2020

@riccardoNovaglia your node version has incomplete support for the package.exports feature. It's also not actively supported by Node.js anymore, see https://nodejs.org/en/about/releases/

Please upgrade to Node.js v14 if you want to use ESM or downgrade to v12 if you want to use CommonJS.

@riccardoNovaglia
Copy link

@ctavan absolutely right. Can confirm it works with both v12 and v14. Thanks for the help!

@asitbiswas
Copy link

update your node. i had the same problem using node 13.3.0 and uuid 8.3.0.

then i upgraded to node 14.12.0 and it worked

@RatonBiswas
Copy link

const { v4 : uuidv4 } = require('uuid');

export { default as v1 } from './v1.js';
^^^^^^
SyntaxError: Unexpected token 'export'

How can I solve this?

@TrySound
Copy link
Member

@RatonBiswas Why do you mix commonjs and es modules? uuid supports both. And what is your environment? We cannot help without additional information.

@RatonBiswas
Copy link

update your node. i had the same problem using node 13.3.0 and uuid 8.3.0.

then i upgraded to node 14.12.0 and it worked

yes, you are right.

@fatihyenidunya
Copy link

if it is still not running after updated node, try update uuid npm install uuid

@guillefix
Copy link

I still have this issue

@ctavan
Copy link
Member

ctavan commented Nov 13, 2020

@guillefix please see: #488 (comment)

@uuidjs uuidjs locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants