Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find mongoose module with webpack #3713

Closed
Amandeepsinghghai opened this issue Dec 24, 2015 · 8 comments · Fixed by #4512
Closed

Cannot find mongoose module with webpack #3713

Amandeepsinghghai opened this issue Dec 24, 2015 · 8 comments · Fixed by #4512
Milestone

Comments

@Amandeepsinghghai
Copy link

Getting the following error with webpack and mongoose - Uncaught Error: Cannot find module '././binary_parser'

Below is my webpack.config.js and the mongoose version I am using is 4.3.3

var path = require('path');
var webpack = require('webpack');
var config = require('./tasks/config');

module.exports = {
  context: path.join(__dirname, 'src'),
  devtool: 'eval',
  historyApiFallback: true,
  entry: {
    app: [
      'webpack-hot-middleware/client',
      './' + config.src.main
    ]
  },
  target: 'node',
  output: {
    path: path.join(__dirname, config.dest),
    filename: 'bundle.js',
    publicPath: '/static/'
  },
  node: {
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
      }
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.IgnorePlugin(/vertx/),
    new webpack.NoErrorsPlugin()
  ],
  resolve: {
    alias: {
      'redux': path.join(__dirname, 'node_modules/redux')
    },
    extensions: ['', '.js', '.json', '.node'],
    fallback: path.join(__dirname, 'node_modules')
  },
  resolveLoader: { fallback: path.join(__dirname, 'node_modules') },
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['react-hot', 'babel'],
      exclude: /node_modules/
    }, {
      test: /\.scss$/,
      loaders: ['style', 'css', 'sass'],
      include: __dirname
    }, {
      test: /\.html$/,
      exclude: /node_modules/,
      loader: 'file?name=[path][name].[ext]'
    }, {
      test: /\.json$/,
      loader: 'json'
    }, {
      test: /\.node$/,
      loader: 'node'
    }]
  }
};

The error is being thrown here

function webpackContextResolve(req) {
    return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
};

Can someone please point me in the right direction????

@vkarpov15
Copy link
Collaborator

#3578 (comment) seems to have gotten it working. I'm unfortunately not familiar with webpack yet (only have tried with browserify) but I'll take a look this week.

@vkarpov15 vkarpov15 added this to the 4.3.5 milestone Jan 4, 2016
@vkarpov15
Copy link
Collaborator

Also, FWIW, there's a pre-built minified version of mongoose on cloudfront: http://d1l4stvdmqmdzl.cloudfront.net/4.3.2/mongoose.min.js if you're not adamant about plugging mongoose into your webpack build. I usually just use the cloudfront version.

@vkarpov15
Copy link
Collaborator

Hmm I think you need the node loader to include mongoose with webpack. Probably not ideal but I'm not an expert on webpack but var mongoose = require('mongoose'); compiles just fine for me using the following config

module.exports = {
  entry: './test.js',
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      { test: /.*/, loader: 'node' }
    ]
  }
};
$ ./node_modules/.bin/webpack ./test.js bundle.js
Hash: 91a588c147e0ef2cbe62
Version: webpack 1.12.9
Time: 83ms
    Asset     Size  Chunks             Chunk Names
bundle.js  2.87 kB       0  [emitted]  main
   [0] multi main 52 bytes {0} [built]
    + 3 hidden modules

@vkarpov15 vkarpov15 added the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Jan 5, 2016
@vodkabears
Copy link

The error is reproduced if you run the app.

@vkarpov15
Copy link
Collaborator

Thanks @vodkabears, above PR should be sufficient to fix this.

@vkarpov15 vkarpov15 added fixed? and removed can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. labels Jan 6, 2016
@vodkabears
Copy link

Yep, i can confirm that mongodb driver with js-bson from the master branch works like a charm in the webpack's bundle right now.

@vodkabears
Copy link

P.S. mongoose has a strict dependency https://github.com/Automattic/mongoose/blob/master/package.json#L23, so you should update it after the release.

@vkarpov15
Copy link
Collaborator

Yep will do, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants