简体   繁体   中英

How to use import & export in node.js?

I have two files :

  1. app.js
  2. module.js

app.js will have expression,

import 'foo' from './module'
//use foo..

and module.js will have,

export default {expression}

But it is not working. I'm currently using Node 7.0.0 I tries using Webpack with babel-loader and es2015 preset but not working.

Your import does not need the quotes, or braces if importing a default export:

import foo from './module';

Also your export should look something like:

export default expression;

and if the exported item is called expression you'd import it as:

import expression from './module';

(you need the braces when importing non-default exports).

Very good in-depth explanation here:

http://www.2ality.com/2014/09/es6-modules-final.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM