找不到模块:错误:无法解决' babel-loader'

时间:2018-06-04 11:48:18

标签: node.js reactjs webpack

我的网页包从2.x升级到4.x.通过执行npm install我收到以下错误

Module not found: Error: Can't resolve 'babel-loader' 

github thread之后,我在webpack.config.json中添加了以下行

 resolveLoader: {   root: path.join(__dirname, 'node_modules') }

但是我收到了以下错误,

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.resolveLoader has an unknown property 'modulesDirectories'. These properties are valid: object { alias?, aliasFields?, cachePredicate?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }

babel-loader版本是7.1.4。 Webpack升级引入了此错误。有什么建议吗?

2 个答案:

答案 0 :(得分:0)

Aren你安装了这个" babel-loader" https://www.npmjs.com/package/babel-loader

module: {
    rules: [{
        test: /\.jsx?$/,
        include: [
            path.resolve(__dirname, 'src/js'),
        ],
        loader: "babel-loader",
        options: {
            presets: ["es2015"],
            plugins: [
                ["babel-plugin-root-import", {
                    "rootPathSuffix": "src/js"
                }],
                [
                    "transform-runtime", {
                        "helpers": false,
                        "polyfill": false,
                        "regenerator": true,
                        "moduleName": "babel-runtime"
                    }
                ],
                "transform-object-assign", "transform-function-bind"
            ]
        },
        // options for the loader
    }}

答案 1 :(得分:0)

只需安装模块:

127.0.0.1 mywebsite.com

npm install babel-loader

我通过运行以上命令解决了这个问题。