javascript - 错误 : Cannot resolve module 'babel-loader'

标签 javascript node.js heroku webpack

当我推送到 heroku 时,我试图在我的 package.json 中的 postinstall 脚本上运行 webpack,但出现以下错误。

ERROR in Entry module not found: Error: Cannot resolve module 'babel-loader' in /tmp/build_6cb4b10367d9382367ab72f2e2f33118

当我在本地运行命令时,我没有遇到任何问题。下面是我的 webpack 配置 - 我尝试使用 resolveLoader 来解决解决问题,但无济于事?

var path = require('path');
var webpack = require('webpack');

var config = {
  entry: path.resolve(__dirname, './app/main.js'),
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader'
      },
      {
        test: /\.less$/,
        loader: 'style!css!less'
      }]
  },
  resolve: {
    extensions: ['', '.js', '.jsx', '.less'],
    modulesDirectories: [
      'node_modules'
    ]
  },
  resolveLoader: {
    root: path.resolve(__dirname, 'node_modules')
  },
  plugins: [
    new webpack.optimize.UglifyJsPlugin({minimize: true})
  ]
};

module.exports = config;

有什么建议吗?谢谢

最佳答案

我找到了原因。我的 package.json 中没有 babel 或 babel-core。添加它们修复了错误。

  "devDependencies": {
    "babel": "^5.8.23",
    "babel-core": "^5.0.0",
    "babel-loader": "^5.3.2"
}

关于javascript - 错误 : Cannot resolve module 'babel-loader' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34538466/

相关文章:

javascript - 检测其他 Atom 包

node.js - 如何在 Swift 中发布一个数组? (获取字节到我的服务器)

windows - “GoDep”未被识别为内部或外部命令

authentication - 使用 Heroku Platform API 进行基本 HTTP 身份验证

postgresql - 在 heroku postgresql 上的一个数据库中创建多个模式

javascript - 基于虚线键父值从平面数组创建关联数组

javascript - 如何检查我的元素 ID 是否具有焦点?

javascript - 如何将JavaScript模块添加到generator-meanjs应用程序?

javascript - 从嵌套异步函数调用返回谓词

javascript - JS中的正则表达式(从字符串中选择标签)