1
我開始用webpack和babel構建一個React應用程序(彈出create-react-app)。不過,我無法使用實用程序功能導入外部.js文件。ES6 + Babel:獲取TypeError:actions.helloOne()不是函數
每當我嘗試撥打actions.helloOne()
時,出現以下錯誤:TypeError: actions.helloOne is not a function
。
我對JS仍然很陌生,所以我可能會錯過一些明顯的東西。
helloActions.js
export function helloOne() {
console.log('one')
}
export function helloTwo() {
console.log('two')
}
actions.js
import { helloOne, helloTwo } from './helloActions'
export {
helloOne,
helloTwo
}
service.js
import * as actions from './actions'
actions.helloOne(); <- undefined
的package.json
"babel-core": "6.22.1",
"babel-eslint": "7.1.1",
"babel-jest": "18.0.0",
"babel-loader": "6.2.10",
"babel-preset-react-app": "^2.2.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-stage-2": "6.5.0",
"babel-plugin-transform-decorators-legacy":"1.3.4",
"babel-plugin-transform-class-properties": "6.11.5",
...
"babel": {
"presets": [
"react-app",
"es2015",
"stage-2"
],
"plugins": ["transform-decorators-legacy","transform-class-properties"]
}
'import * as actions'?爲什麼不「輸入動作」? – evolutionxbox
這很奇怪。它對我來說工作得很好。 – Li357
@AndrewLi對,我看起來100%正確,所有其他的例子也是一樣的。它可能是巴貝爾或其他東西的壞版本? –