繁体   English   中英

无法解析“babel-loader”

[英]Can't resolve 'babel-loader'

我正在尝试配置我的第一个节点反应应用程序。

我不断收到一条错误消息,提示“无法解析 babel-loader”。

谷歌搜索那个错误,我发现了一些不起作用的建议。

首先是在我的webpack.config.js中添加以下内容

// resolveLoader: {
  //       modulesDirectories: '/usr/local/lib/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? }

下一个建议是尝试:

resolveLoader: {
        fallback: '/usr/local/lib/node_modules'
    },

这会产生类似的错误。

有没有人对如何开始使用此配置有任何建议。 事实证明,理解文档很困难——每一个单词都是行话,我找不到一个参考点来基本理解需要做什么才能开始这个设置。

Webpack.config.js 是:

module.exports = {
  entry: './app/app.jsx',
  output: {
    path: __dirname,
    filename: './public/bundle.js'
  },

  resolve: {
    modules: [__dirname, 'node_modules'],
    alias: {
      Greeter: 'app/components/Greeter.jsx',
      GreeterMessage: 'app/components/GreeterMessage.jsx',
      GreeterForm: 'app/components/GreeterForm.jsx',

    },
    extensions: ['.js', '.jsx']
  },

  // resolveLoader: {
  //       fallback: '/usr/local/lib/node_modules'
  //   },

  module :{
    rules:[{
      // use : 'babel-loader',
      loader: 'babel-loader',
      query :{
        presets:['react','es2015']
        // ,'es2017'
      },
      test: /\.jsx?$/,
      exclude: /(node_modules|bower_components)/
    }
   ]
 }


};

我有同样的问题; 我通过安装 babel-loader 模块修复了它:

yarn add -D babel-loader

npm install --save babel-loader

暂无
暂无

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

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