鍍金池/ 問答/HTML/ babel編譯后提示import的值無法讀取

babel編譯后提示import的值無法讀取

目錄結(jié)構(gòu)是這樣的
圖片描述

上代碼
profile.js

function showMsg(msg) {
    alert(msg);
}
export default {showMsg};

import.js

import {showMsg} from "./profile.js";

showMsg("hello world");

.babelrc

{
    "presets":[
        "es2015"
    ],
    "plugins":["transform-es2015-modules-umd"]
}

package.json

{
  "name": "module",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "babel src/import.js -o dist/index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-plugin-transform-es2015-modules-umd": "^6.24.1",
    "babel-preset-es2015": "^6.24.1"
  }
}

運行后提示 Cannot read property 'showMsg' of undefined

回答
編輯回答
病癮

profile.js

function showMsg(msg) {

alert(msg);

}
export {showMsg};

刪除 default

2017年10月2日 17:41