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
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.
I know that this is an old question. But in case others still look for alternative, now with the new Node version, we can use without Babel:
https://nodejs.org/api/esm.html
So what you need to do is upgrading your Node version. FYI: This Node version v10.9.0 is still experimental.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With