Babel doesn't see shared lib


my project is structured:

    |- node_modules
    |- lib
         |- shared.js
    |- service1
        | - serverless.yml
        | - webpack.config.js
        | - service1.js <-- import Something from '../lib/shared';


const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  externals: [nodeExternals({modulesDir:'../node_modules'})],
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['babel-loader'],
      include: __dirname,
      exclude: /node_modules/,
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'

The file in lib/shared.js is not being Babel compiled and the build is failing because of ES6 syntax (if I move to the ./service1 dir everything is fine)


Looks like your include is only including the current directory and not the lib/shared

Where is babel config defined?

1 Like

ok - so I had tried [ __dirname, ‘…/lib’ ] but that didn’t work. Thanks to your note I was inspired to look again and:

include: [__dirname, path.join(__dirname, '../lib')],

did the trick! Thanks!

1 Like