`babel`的节点API已被移动到`babel-core` React webpack

时间:2017-06-21 05:10:33

标签: node.js reactjs react-native webpack

我尝试使用我的React原生Android应用作为网站。我跟着这个tutorial

当我运行webpack-dev-server时显示错误。

enter image description here

webpak.cofig.js

module.exports = {
    entry: "./entry.js",
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'stage-0', 'react']
                }
            }
        ]
    },
    resolve: {
        alias: {
            "react-native": "react-native-web"
        }
    }
};

entry.js

document.write(require('./../testreact/index.android.js'));

的package.json

{
    "name": "testreact",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "start": "adb reverse tcp:8081 tcp:8081 && node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
    },
    "dependencies": {
        "babel": "^6.23.0",
        "babel-polyfill": "^6.23.0",
        "babel-preset-es2015": "^6.24.1",
        "babel-preset-react": "^6.24.1",
        "babel-preset-stage-0": "^6.24.1",
        "firebase": "^4.1.2",
        "react": "^16.0.0-alpha.12",
        "react-native": "0.45.1",
        "react-native-router-flux": "^3.38.0",
        "react-native-web": "0.0.104",
        "react-navigation": "^1.0.0-beta.11",
        "webpack": "^3.0.0",
        "webpack-dev-server": "^2.5.0"
    },
    "devDependencies": {
        "autoprefixer": "^7.1.1",
        "babel-core": "^6.25.0",
        "babel-jest": "20.0.3",
        "babel-loader": "^7.1.0",
        "babel-preset-react-native": "2.0.0",
        "jest": "20.0.4",
        "react-test-renderer": "16.0.0-alpha.12"
    },
    "jest": {
        "preset": "react-native"
    }
}

更新

enter image description here

1 个答案:

答案 0 :(得分:0)

如果尚未解决此问题,请在您的webpack config文件中使用babel-loader代替babel-core