Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Export, import modules #625

Closed
huytran0605 opened this issue Jul 20, 2017 · 3 comments
Closed

[Question] Export, import modules #625

huytran0605 opened this issue Jul 20, 2017 · 3 comments

Comments

@huytran0605
Copy link

Currently, my project base on feather-cli and i need to use import, export module instead of require
But i got the error SyntaxError: Unexpected token export when i try to use import, export.
I saw some issue make feather turn back into commonjs.
I understand after #608 approve and merged, i can use import, export without error.
So my question is what can i do to use import & export instead of require ?

@subodhpareek18
Copy link

You could use babel-register to bootstrap your code as it runs.

// package.json
}
  "dependencies": {
  "babel-preset-es2015": "^6.24.1",
  "babel-register": "^6.24.1",
  ...
}
// .babelrc
{
  "presets": ["es2015"]
}
// index.js < main entry point
require('babel-register');
require('./server').run();
// server.js < your actual code here
import express from 'express';
export const run () => {
     const app = express()
     ......
}

Or you could simply transpile the code using babel in case you do not want to use babel-register at runtime.

@daffl
Copy link
Member

daffl commented Jul 20, 2017

The generated application will always only use what the latest version of Node supports (we'll probably update it to use async/await for the next version). You can find more of the reasoning behind not using Babel by default in feathersjs-ecosystem/generator-feathers#31 and a discussion in feathersjs-ecosystem/cli#91 (including the challenges of updating our generator codemods to the new syntax).

In summary, using ES modules with Babel will increase startup/compile time and possibly memory consumption just to use a spec whose implementation details (especially for Node) have not been fully finalized.

If you still want to use it, you can probably run the generated code through a require to ES module tranformer with the Babel setup that @zusamann pointed out.

@lock
Copy link

lock bot commented Feb 7, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants