Search code examples
node.jsuuid

Can't use import syntax Error while importing uuid


I am trying to import uuid like

import { v1 as uuidv1 } from 'uuid';

But I get a syntax error

Cannot use import statement outside a module


Solution

  • because nodejs doesn't support BABEL!

    try:

    const { v1 as uuid} = require('uuid');
    

    If you need BABEL you must add it and enable it: look this: https://dev.to/ganeshmani/configuring-babel-for-node-js-express-server-35hp or google it.