I'm trying to setup a nodejs lambda service which uses mongoose to connect to a mongodb.
Summary
The webpack call contains some warning and no error. The lambda service returns "Cannot find module './node-mongodb-native'."
Related Links
- Trying to use mongoose in nodejs app using Webpack as module Bundler
- https://github.com/webpack/webpack/issues/1040
- https://github.com/Automattic/mongoose/issues/3578
- Trying to use mongoose with node-webkit target on Webpack
Details
The webpack call returns
./node_modules/.bin/webpack -p --config config/webpack.config.babel.js --display-error-details
...
WARNING in ./~/mongoose/lib/drivers/index.js
Critical dependencies:
8:11-74 the request of a dependency is an expression
@ ./~/mongoose/lib/drivers/index.js 8:11-74
WARNING in ./~/mongoose/lib/drivers/SPEC.md
Module parse failed: /pathReplacement/node_modules/mongoose/lib/drivers/SPEC.md Unexpected character '#' (2:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '#' (2:0)
at Parser.pp.raise (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:920:13)
at Parser.pp.getTokenFromCode (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:2813:8)
at Parser.pp.readToken (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:2508:15)
at Parser.pp.nextToken (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:2500:71)
at Parser.parse (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:1615:10)
at Object.parse (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:882:44)
at Parser.parse (/pathReplacement/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock.<anonymous> (/pathReplacement/node_modules/webpack/lib/NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (/pathReplacement/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/pathReplacement/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /pathReplacement/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/pathReplacement/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at /pathReplacement/node_modules/webpack/node_modules/enhanced-resolve/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
@ ./~/mongoose/lib/drivers ^\.\/.*$
WARNING in ./~/mongoose/~/bson/lib/bson/index.js
Critical dependencies:
20:16-29 the request of a dependency is an expression
44:18-31 the request of a dependency is an expression
71:19-32 the request of a dependency is an expression
@ ./~/mongoose/~/bson/lib/bson/index.js 20:16-29 44:18-31 71:19-32
WARNING in ./~/mongoose/~/mongodb/~/es6-promise/dist/es6-promise.js
Module not found: Error: Cannot resolve module 'vertx' in /pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/es6-promise/dist
resolve module vertx in /pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/es6-promise/dist
looking for modules in /pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules
/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx doesn't exist (module as directory)
resolve 'file' vertx in /pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules
resolve file
/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.json doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.js doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.jsx doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.es6 doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.babel doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.node doesn't exist
looking for modules in /pathReplacement/node_modules/mongoose/node_modules
/pathReplacement/node_modules/mongoose/node_modules/vertx doesn't exist (module as directory)
resolve 'file' vertx in /pathReplacement/node_modules/mongoose/node_modules
resolve file
/pathReplacement/node_modules/mongoose/node_modules/vertx doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/vertx.js doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/vertx.json doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/vertx.jsx doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/vertx.es6 doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/vertx.babel doesn't exist
/pathReplacement/node_modules/mongoose/node_modules/vertx.node doesn't exist
looking for modules in /pathReplacement/node_modules
/pathReplacement/node_modules/vertx doesn't exist (module as directory)
resolve 'file' vertx in /pathReplacement/node_modules
resolve file
/pathReplacement/node_modules/vertx doesn't exist
/pathReplacement/node_modules/vertx.js doesn't exist
/pathReplacement/node_modules/vertx.json doesn't exist
/pathReplacement/node_modules/vertx.jsx doesn't exist
/pathReplacement/node_modules/vertx.es6 doesn't exist
/pathReplacement/node_modules/vertx.babel doesn't exist
/pathReplacement/node_modules/vertx.node doesn't exist
[/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx]
[/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx]
[/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.json]
[/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.js]
[/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.jsx]
[/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.es6]
[/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.babel]
[/pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/vertx.node]
[/pathReplacement/node_modules/mongoose/node_modules/vertx]
[/pathReplacement/node_modules/mongoose/node_modules/vertx]
[/pathReplacement/node_modules/mongoose/node_modules/vertx.js]
[/pathReplacement/node_modules/mongoose/node_modules/vertx.json]
[/pathReplacement/node_modules/mongoose/node_modules/vertx.jsx]
[/pathReplacement/node_modules/mongoose/node_modules/vertx.es6]
[/pathReplacement/node_modules/mongoose/node_modules/vertx.babel]
[/pathReplacement/node_modules/mongoose/node_modules/vertx.node]
[/pathReplacement/node_modules/vertx]
[/pathReplacement/node_modules/vertx]
[/pathReplacement/node_modules/vertx.js]
[/pathReplacement/node_modules/vertx.json]
[/pathReplacement/node_modules/vertx.jsx]
[/pathReplacement/node_modules/vertx.es6]
[/pathReplacement/node_modules/vertx.babel]
[/pathReplacement/node_modules/vertx.node]
@ ./~/mongoose/~/mongodb/~/es6-promise/dist/es6-promise.js 132:20-30
WARNING in ./~/mongoose/~/mongodb/~/mongodb-core/~/require_optional/index.js
Critical dependencies:
63:18-42 the request of a dependency is an expression
71:20-44 the request of a dependency is an expression
78:35-67 the request of a dependency is an expression
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/require_optional/index.js 63:18-42 71:20-44 78:35-67
WARNING in ./~/mongoose/~/mongodb/~/mongodb-core/~/require_optional/README.md
Module parse failed: /pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/require_optional/README.md Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '#' (1:0)
at Parser.pp.raise (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:920:13)
at Parser.pp.getTokenFromCode (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:2813:8)
at Parser.pp.readToken (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:2508:15)
at Parser.pp.nextToken (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:2500:71)
at Parser.parse (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:1615:10)
at Object.parse (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:882:44)
at Parser.parse (/pathReplacement/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock.<anonymous> (/pathReplacement/node_modules/webpack/lib/NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (/pathReplacement/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/pathReplacement/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /pathReplacement/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/pathReplacement/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at /pathReplacement/node_modules/webpack/node_modules/enhanced-resolve/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/require_optional ^\.\/.*$
WARNING in ./~/mongoose/~/mongodb/~/mongodb-core/~/require_optional/LICENSE
Module parse failed: /pathReplacement/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/require_optional/LICENSE Unexpected token (1:40)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:40)
at Parser.pp.raise (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:920:13)
at Parser.pp.unexpected (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:1483:8)
at Parser.pp.semicolon (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:1462:73)
at Parser.pp.parseExpressionStatement (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:1976:8)
at Parser.pp.parseStatement (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:1754:188)
at Parser.pp.parseTopLevel (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:1648:21)
at Parser.parse (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:1616:17)
at Object.parse (/pathReplacement/node_modules/webpack/node_modules/acorn/dist/acorn.js:882:44)
at Parser.parse (/pathReplacement/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock.<anonymous> (/pathReplacement/node_modules/webpack/lib/NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (/pathReplacement/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/pathReplacement/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /pathReplacement/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/pathReplacement/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at /pathReplacement/node_modules/webpack/node_modules/enhanced-resolve/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/require_optional ^\.\/.*$
WARNING in index.js from UglifyJs
Side effects in initialization of unused variable f [./~/mongoose/~/mongodb/lib/utils.js:4,0]
Dropping unreachable code [./~/mongoose/~/mquery/~/bluebird/js/main/util.js:210,0]
Non-strict equality against boolean: == true [./~/mongoose/~/mongodb/~/mongodb-core/lib/connection/utils.js:10,0]
...
Executing lambda throws the following error: Cannot find module './node-mongodb-native'.**
cd build
node-lambda run
analytics tracker was created
skill was created
Error: Error: Cannot find module './node-mongodb-native'.
webpack.config.babel.js
import Path from 'path';
import webpack from 'webpack';
const path = (...parts) => Path.join(__dirname, '..', ...parts);
export default {
entry: ['babel-polyfill', path('src', 'index.js')],
devtool: 'source-map',
target: 'node',
output: {
libraryTarget: 'commonjs',
library: 'handler',
filename: 'index.js',
path: path('build'),
},
module: {
loaders: [
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
{
test: /\.node$/,
loader: 'node-loader',
},
],
},
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(true),
],
resolve: {
extensions: ['', '.js', '.json', '.jsx', '.es6', '.babel', '.node'],
modulesDirectories: ['node_modules'],
},
node: {
console: true,
fs: 'empty',
net: 'empty',
tls: 'empty',
},
};