5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nodeでimportを使う

Posted at

import使ったらSyntax Errorで怒られたのでメモ

必要なpackage

nodeを使用して、babel6.x系でimportを使用するには、

babel-cli
babel-preset-es2015
babel-preset-stage-2
babel-register

この辺のパッケージをnpm installしましょう。devDependencyです。

実行方法

package.jsonのscriptsには

"start": "babel-node lib/index.js --exec babel-node --presets es2015,stage-2"

を足しましょう。これでimport使えます。

ただし、本番環境(production)でbabel-nodeで使ってはいけません。
https://babeljs.io/docs/usage/cli/#babel-node

ちゃんとbuildしましょう。

参考リポジトリ
https://github.com/babel/example-node-server

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?