ES6 import in init script

I’m currently using javascript for my init script and trying to use ES6 import syntax for module system.
I know that require will do the job I want, but I just wanted to use new features this time.
When I try import("path"), atom gives the following error:

Failed to resolve module specifier ‘path’

Similar error comes out when I try import("./local-module"), import("./local-module.js"), import(`${__dirname}/local-module.js`).
How can I use import syntax from init script?

The import syntax is different than the one used for require…

Whereas you usually do:

const x = require(‚x‘)

You will have to write:

import * as x from ,x‘

Check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import for the details!

More specifically, you can use one of the following:

import path from 'path';
import { join, resolve } from 'path';
import { join as myJoin } from 'path';

I already know how the typical import syntax looks like. I tried the suggested code before, and it gives Unexpected token * error. Maybe js engine used in atom doesn’t support this syntax yet.

However, when I try the dynamic version of import syntax (which is also stated in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import), it seems atom is trying to do something. Guessing from the call stack and error message, I think it’s trying to load module from some path. I just wanted to know if I could use this thing instead of require.

By the way, it’s the first time I’ve seen the syntax like ,x'. What’s that?

Sorry that was just an autocorrect on my mobile… as Atom is based on a certain version of Electron, which itself uses a specific combination of nodejs and chromium, it eventually falls down to the question: does the bundled version of nodejs allow ES6 imports… looks like there are some challenges: https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node

If I’m not mistaken, even Node v11 does not support import unless you use a flag or transpile the code, so it should be the same with with versions bundled with Atom

Edit: Whoops, the answer was already given in the previous post :sweat_smile: