How to import class using ES6 syntax? (without Babel)

Oleksii

I have file with a ES6 class with default export:

accessmanager.js

   export default class AccessManagerClient {
      constructor(){
        ...
      }
    }

And I want to import it like this:

anotherFile.js

import AccessManagerClient from '../someFolder/accessmanager';

When I run my spec I get an error:

import AccessManagerClient from '../someFolder/accessmanager';
^^^^^^

SyntaxError: Unexpected token import

I have such npm and node versions:

$ npm -v
5.3.0

$ node -v
v8.0.0
T.J. Crowder

You can't without Babel or some other packager/bundler/transpiler, because Node doesn't have native support for import/export yet. Either use Node's own modules, or a packager/bundler/transpiler.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Javascript

import class and call static method with es6 modules with babel transpiler

From Javascript

In the `import` syntax of ES6, how is a module evaluated exactly?

From Javascript

How to import jquery using ES6 syntax?

From Javascript

Exporting a class with ES6 (Babel)

From Dev

Relative Dynamic Loading with systemJS, using ES6/Babel syntax

From Dev

Converting jsx with ES6 import syntax using reactify

From Dev

How to install babel and using ES6 locally on Browser?

From Dev

How to import .html fragment using es6 syntax in TypeScript

From Dev

How will browsers handle ES6 import/export syntax

From Dev

Dynamically import JavaScript module using ES6 syntax?

From Dev

Use RequireJS to include a class defined using ES6 syntax

From Dev

How to inject dependencies in Aurelia without using ES6 class feature

From Dev

How to set up Ramda in Rollup with Babel (to use ES6 import)

From Dev

ES6/Babel Class constructor cannot be invoked without 'new'

From Dev

TypeScript: How to import an ES6 JavaScript class?

From Dev

Webpack with Babel lazy load module using ES6 recommended Import() approach not working

From Dev

How to export and import class properly in javascript ES6

From Dev

how to use node module with es6 import syntax in typescript

From Dev

How to import Firebase Firestore into a create-react-app project using ES6 syntax

From Dev

Syntax Error on dynamic import() using webpack and babel

From Dev

JS: enabling export/import on client side (ES6 or using babel)?

From Dev

In typescript, how can I import a plain javascript file with a default export using es6 syntax?

From Dev

How to import firebase-functions and firebase-admin in ES6 syntax for transpiling with Babel for Node 10

From Dev

How to import pg-promise using ES6 syntax?

From Dev

How to subclass an Ember class using ES6 syntax in Ember CLI

From Dev

Importing/exporting the Express router using ES6 import + export keywords and Babel

From Dev

ReactJS : How to import ES6 custom class ?

From Dev

How to alias a prototype function using es6 syntax

From Dev

Chessjs cannot be imported without using es6 syntax

Related Related

  1. 1

    import class and call static method with es6 modules with babel transpiler

  2. 2

    In the `import` syntax of ES6, how is a module evaluated exactly?

  3. 3

    How to import jquery using ES6 syntax?

  4. 4

    Exporting a class with ES6 (Babel)

  5. 5

    Relative Dynamic Loading with systemJS, using ES6/Babel syntax

  6. 6

    Converting jsx with ES6 import syntax using reactify

  7. 7

    How to install babel and using ES6 locally on Browser?

  8. 8

    How to import .html fragment using es6 syntax in TypeScript

  9. 9

    How will browsers handle ES6 import/export syntax

  10. 10

    Dynamically import JavaScript module using ES6 syntax?

  11. 11

    Use RequireJS to include a class defined using ES6 syntax

  12. 12

    How to inject dependencies in Aurelia without using ES6 class feature

  13. 13

    How to set up Ramda in Rollup with Babel (to use ES6 import)

  14. 14

    ES6/Babel Class constructor cannot be invoked without 'new'

  15. 15

    TypeScript: How to import an ES6 JavaScript class?

  16. 16

    Webpack with Babel lazy load module using ES6 recommended Import() approach not working

  17. 17

    How to export and import class properly in javascript ES6

  18. 18

    how to use node module with es6 import syntax in typescript

  19. 19

    How to import Firebase Firestore into a create-react-app project using ES6 syntax

  20. 20

    Syntax Error on dynamic import() using webpack and babel

  21. 21

    JS: enabling export/import on client side (ES6 or using babel)?

  22. 22

    In typescript, how can I import a plain javascript file with a default export using es6 syntax?

  23. 23

    How to import firebase-functions and firebase-admin in ES6 syntax for transpiling with Babel for Node 10

  24. 24

    How to import pg-promise using ES6 syntax?

  25. 25

    How to subclass an Ember class using ES6 syntax in Ember CLI

  26. 26

    Importing/exporting the Express router using ES6 import + export keywords and Babel

  27. 27

    ReactJS : How to import ES6 custom class ?

  28. 28

    How to alias a prototype function using es6 syntax

  29. 29

    Chessjs cannot be imported without using es6 syntax

HotTag

Archive