我尝试在webpack.config.js中添加babel-preset-stage 0 以下是我配置的代码:
module.exports = {
entry: './app/app.jsx',
output: {
path: __dirname,
filename: './public/bundle.js'
},
resolve: {
root: __dirname,
alias: {
},
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
loader: 'babel-loader',
query: {
presets: ['stage-0', 'react', 'es2015']
},
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/
}
]
}
};

但是,我最终得到了这个错误:
ERROR in ./app/app.jsx
Module build failed: TypeError: Path must be a string. Received undefined
at assertPath (path.js:28:11)
at Object.dirname (path.js:1345:5)
at /Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:374:36
at /Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:396:22
at Array.map (native)
at OptionManager.resolvePresets (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:385:20)
at OptionManager.mergePresets (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:369:10)
at OptionManager.mergeOptions (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328:14)
at /Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:370:14
at /Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:390:24
at Array.map (native)
at OptionManager.resolvePresets (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:385:20)
at OptionManager.mergePresets (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:369:10)
at OptionManager.mergeOptions (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328:14)
at OptionManager.init (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/options/option-manager.js:481:10)
at File.initOptions (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/index.js:211:75)
at new File (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/file/index.js:129:22)
at Pipeline.transform (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-core/lib/transformation/pipeline.js:48:16)
at transpile (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-loader/index.js:14:22)
at Object.module.exports (/Users/annguyen/Documents/React/ReactWeather/node_modules/babel-loader/index.js:88:12)

当我删除' stage-0'在预设中,它工作得非常好。 这是我的开发依赖项:
"devDependencies": {
"babel-core": "^6.5.1",
"babel-loader": "^6.2.2",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.24.1",
"webpack": "^1.12.13"
}

答案 0 :(得分:0)
建议您在项目的根目录中添加.babelrc
,然后:
{
"presets": [
"es2015",
"stage-0",
"react"
]
}