1. 程式人生 > >babel & browserify 報錯 'import' and 'export' may appear only with 'sourceType: module' (2:0)

babel & browserify 報錯 'import' and 'export' may appear only with 'sourceType: module' (2:0)

使用babel & browserify, 當在A檔案:

export default function method() { ... };

在B檔案:

import utils from './A';
將報錯:'import' and 'export' may appear only with 'sourceType: module' (2:0)

解決辦法:

需要新建檔案.babelrc, 輸入: 

{
  "presets": ["es2015", "stage-0"]
}