Skip to content

Multiple entries with nested folder structure - error resolving 'file' or 'directory' due to missing named files in folder(s) #1906

@ConAntonakos

Description

@ConAntonakos

Hi. I apologize if this was asked; I could not find duplicate(s).

I basically have a hierarchical folder structure like a lot of people probably. The issue I'm having is that I'm getting errors like so: ERROR in multi components Module not found: Error: Cannot resolve 'file' or 'directory'. After delving deeper into the details it looks like webpack is looking for a charting.js or a charting/index.js kind of structure, but I basically want the folders to organize my files; not necessarily force what files should be in there as dictated by webpack.

|-- node_modules
|-- public
  |-- components
    |-- charting
    |-- reporting
    ...

For example, another folder hierarchy is:

|-- public
  |-- components
    |-- routing
      |-- views
        |-- admin
          |-- App.jsx

Webpack is requiring that I add an index.js or something like that to each nested folder, but that is something I want to avoid. Any ideas how I can improve this? Should I try and flatten? Thanks!

My config:

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

var config = require('./gulp/config.js');

var rawScriptsPath = path.resolve(__dirname + '/' + config.path.publicBase + '/scripts');

module.exports = {
  context: rawScriptsPath,
  entry: {
    core: rawScriptsPath + '/core/application.js',
    components: glob.sync(rawScriptsPath + '/components/**/!(sf\.)*'),
    reporting: glob.sync(rawScriptsPath + '/reporting/**/!(\.clients)')
  },
  output: {
    path: path.resolve(__dirname, 'public/dist/scripts'),
    filename: '[name].js'
  },
  resolve: {
    extensions: ['', '.js', '.jsx'],
    modulesDirectories: [
      'node_modules',
      rawScriptsPath
    ],
    root: rawScriptsPath
  },
  module: {
    loaders: [      
      { 
        test: /\.js(x?)$/, 
        exclude: /node_modules/, 
        loader: 'babel', 
        query: { 
          stage: 0
          // presets: ['es2015', 'stage-0', 'react']
        } 
      },
      { 
        test: /\.css$/, 
        exclude: /node_modules/, 
        loaders: [
          'style',
          'css'
          // 'autoprefixer?browsers=last 3 versions',
          // 'sass?outputStyle=expanded'
        ]
      }
    ]
  },
  plugins: [
    new webpack.NoErrorsPlugin(),
    new webpack.IgnorePlugin(/\.svn$/)
  ]
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions