Issue 1:
By default babel is looking for node_modules in current directory.

But sometimes we need to use node_modules from some child or other directory.

I tried to use NODE_PATH env, but it doesn't work.

So, maybe it's good idea to add supporting some environment variable, for example BABEL_NODE_MODULES with list of path to search node_modules directory.

Let's make babel more flexible!

Issue 2:
This is a bug report - I am getting this error:

Module build failed: Error: Couldn't find preset "latest" relative to directory "/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman-browser-polyfills/modules"
at /Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map (native)
at OptionManager.resolvePresets (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transpile (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-loader/lib/index.js:46:20)
at Object.module.exports (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-loader/lib/index.js:163:20)
@ ./lib/index.js 136:9-22
@ multi babel-polyfill ./lib/index.js

ERROR in .-browser-polyfills/modules/assert.js
Module build failed: Error: Couldn't find preset "latest" relative to directory "/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman-browser-polyfills/modules"
at /Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map (native)
at OptionManager.resolvePresets (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transpile (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-loader/lib/index.js:46:20)
at Object.module.exports (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/babel-loader/lib/index.js:163:20)
@ ./lib/index.js 131:13-30
@ multi babel-polyfill ./lib/index.js

Webpack should be able to find the babel modules, because I am using NODE_PATH, which allows me to store Babel deps in a particular location, and I run webpack like so:

#!/usr/bin/env bash
NODE_PATH=${NODE_PATH}:~/.suman/global/node_modules webpack

I have this webpack config:

const path = require('path');

module.exports = {

entry: ['babel-polyfill', './lib/index.js'],

output: {
path: path.resolve(__dirname + '/dist'),
filename: 'suman.js'
},

module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: ['latest'],
plugins: ['transform-runtime']
}
},
{
test: /(\/lib\/init\/|cli.js$)/,
loader: 'ignore-loader'
}
]
},

resolve: {
alias: {
fs: require.resolve('suman-browser-polyfills/modules/fs'),
assert: require.resolve('suman-browser-polyfills/modules/assert')
},
extensions: ['.js']
},

node: {
// assert: true,
buffer: true,
child_process: 'empty',
cluster: 'empty',
console: true,
constants: true,
crypto: 'empty',
dgram: 'empty',
dns: 'mock',
domain: true,
events: true,
// fs: 'empty',
http: true,
https: true,
module: 'empty',
net: 'mock',
os: true,
path: true,
process: true,
punycode: true,
querystring: true,
readline: 'empty',
repl: 'empty',
stream: true,
string_decoder: true,
timers: true,
tls: 'mock',
tty: true,
url: true,
util: true,
v8: 'mock',
vm: true,
zlib: 'empty',
}
};

as you can see, in resolve.alias, we are referencing another project. No Babel dependencies are installed in

But that should not matter, the Babel deps needed are located in the directory referenced in NODE_PATH.

What's probably happening is that Webpack/Babel is doing a relative path lookup check for the needed Babel deps, but it should also check on NODE_PATH, if it needs to do a "pre-check".