It seems there is a problem with exporting different versions inside of uuid. My project is using uuidv4 which is using uuid.
Steps to reproduce the behavior:
Expected to run without problem.
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'
This point is not clear. Is it node project or some bundler, which bundler?
Run project (commonJs style)
It is node project... I guess it happens because of my node written in commonJs and uuid is es6!
Nope. UUID is distributed as commonjs by default.
https://unpkg.com/browse/[email protected]/dist/index.js
How do you import uuid? And provide please minimal reproduction.
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????
Show how do you import uuid, give us a reproduction.
This is how i import:
const { uuid } = require('uuidv4');
This package?
https://www.npmjs.com/package/uuidv4
The wrong one. Please read documentation.
I see. This package is the dependency of your one. Could you switch to using uuid package directly?
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/
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
@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.
@ctavan absolutely right. Can confirm it works with both v12 and v14. Thanks for the help!
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
const { v4 : uuidv4 } = require('uuid');
export { default as v1 } from './v1.js';
^^^^^^
SyntaxError: Unexpected token 'export'
How can I solve this?
@RatonBiswas Why do you mix commonjs and es modules? uuid supports both. And what is your environment? We cannot help without additional information.
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.
if it is still not running after updated node, try update uuid npm install uuid
I still have this issue
@guillefix please see: https://github.com/uuidjs/uuid/issues/488#issuecomment-664585063
Most helpful comment
@riccardoNovaglia your node version has incomplete support for the
package.exportsfeature. It's also not actively supported by Node.js anymore, see https://nodejs.org/en/about/releases/Please upgrade to Node.js
v14if you want to use ESM or downgrade tov12if you want to use CommonJS.