繁体   English   中英

找不到模块:错误:无法解析“babel-loader”

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

只是我将我的网络包从 2.x 升级到 4.x。 通过执行 npm install 我收到以下错误

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

github 线程之后,我在 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 升级引入了这个错误。 对此有何建议?

你是不是安装了这个“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
    }}

只需安装模块:

npm install babel-loader

或者

yarn add babel-loader

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM