I guess I’m not really understanding how import / exports work because I’m can never get it to work properly.
index.js
import './app';
/* or import { run } from './app'; */
run();
app.js
function run() {
console.log('success');
}
export default run;
What am I doing wrong?
the exporting module is exporting the run
function as its default export, so when you import it, you wuold
import run /* or myRun */ from './app'
// the default export would be assigned to your local binding
//then call it
run();
More information on MDN
doesnt work for me dude. thats literally what I have
import run from './app';
run();
error
(function (exports, require, module, __filename, __dirname) { import run from './app';
could you provide some context in which this error is happening ?
I have a folder with 2 files. One named index.js and one named app.js
index.js
import run from './app';
run();
app.js
function run() {
console.log('success');
}
export default run;
are you trying to run them directly with nodejs like: node index.js
?
if yes, please note that nodejs does not yet support es6 modules directly, and you would need a build system like webpack
or use a simpler approach like esm
yeah that was the problem. wasnt using node index.js
but i had to compile first. thx man