【问题标题】:Can't resolve 'babel-loader'无法解析“babel-loader”
【发布时间】:2017-11-13 09:37:41
【问题描述】:

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

我不断收到“无法解析 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模块了吗?
  • 请告诉我们your webpack.config.js
  • @chenkehxx - 是的,babel-loader 在我的开发依赖项中
  • 检查你的 webpack 是什么版本,1.x2.x
  • webpack 是 v2.6.1

标签: node.js webpack babeljs node-modules webpack-2


【解决方案1】:

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

yarn add -D babel-loader

npm install --save babel-loader

【讨论】:

  • 应该是 yarn add -D babel-loader 吗?你有什么理由在生产中需要这个?
  • 谢谢,@JulianK -- 我已经确定了答案!
猜你喜欢
  • 2017-10-05
  • 2017-08-04
  • 2016-04-04
  • 2016-11-09
  • 1970-01-01
  • 2020-11-18
  • 1970-01-01
  • 2019-10-27
  • 2020-02-02
相关资源
最近更新 更多