javascript - Why is webpack trying to parse every file in my dependency's path? -


i have large project i've been refactoring use webpack , es6 modules. many of dependencies using commonjs or amd modules, i'm requiring them old way.

for example,

const pikaday = require("pikaday"); 

unfortunately, when run

webpack --progress 

it looks webpack trying parse every single file in path. several warnings like, example:

module parse failed: /path/to/node_modules/pikaday/index.html  

eventually, following error:

error in ./~/pikaday/tests/methods.js module not found: error: cannot resolve module 'expect.js' in  /users/myuser/web/myproject/node_modules/pikaday/tests 

i'm getting error tests directory in dependency, don't care parsing bundle. why webpack trying parse every file in path, , how correct behavior?


for clarity, i'll post important parts of webpack.config.js file here.

var webpack = require("webpack"); var path = require("path");  module.exports = {     entry : {         main     : './public/src/main/main.js',        },     output : {         path        : './public/build',         filename    : '[name].bundle.js'     },     module : {         loaders : [             {                 test : /\.json$/,                 loader : 'json'             },             {                 test : /\.js$/,                 loader : "babel?presets[]=es2015"             },             {                 test    : /\.css$/,                 loaders  : [                     'style',                     'css'                 ]             },             {                 test: /\.scss$/,                 loaders: ["style", "css", "sass"]             },             {                 test    : /\.(svg|jpg|png|jpeg)$/,                 loader  : 'url'             },             {                 test : /vendor\/.+\.(jsx|js)$/,                 loader : 'imports?jquery=jquery,$=jquery,this=>window'             }         ]     },     "plugins" : [         new webpack.provideplugin({             $               : "jquery",             jquery          : "jquery",             "window.jquery" : "jquery"         }),         new webpack.provideplugin({             $clamp : "clamp-js"         }),         new webpack.provideplugin({          })     ] }; 

when processing modules, webpack analyses of dependencies reachable own code, traversing through everything. attempt process both amd or commonjs style code.

in case, module loading not appear use format of loading dependencies webpack can analyse properly. when code here:

var id = 'moment'; try { moment = req(id); } catch (e) {} 

runs, webpack not smart enough see req(id) req('moment'). because has no way of knowing id is, consider req(id) possibly loading any file inside pikaday module, you're seeing, includes tests folder, , index.html file, both of causing issues you.

in case lucky because while amd section of module not parsable, module includes commonjs prefix here, is parsable webpack. because of that, should able follow instructions is there way disable amdplugin? make webpack stop processing amd modules, , use commonjs section of code.

keep in mind, if need depend on amd modules, break those, things commonjs these days anyway.

either way, file bug on pikaday module, since should trivial fix in module itself.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -