How would I import a module within an npm package subfolder with webpack? -


lets theres package in node_modules called foo , want import module within library such foo/module via webpack & babel...

import foo 'foo'; works

import someothermodule 'foo/module'; fails following:

module not found: error: cannot resolve module 'foo/module' in /users/x/desktop/someproject/js

which makes make seem webpack looking file in wrong place instead of node_modules

my webpack.config looks this:

var webpack = require('webpack'); var path = require('path');  module.exports = {     entry: ['babel-polyfill','./js/script.js'],     output: {         path: __dirname,         filename: './build/script.js'     },     module: {         loaders: [             {                 test: /\.js$/,                 loader: 'babel',                 query: {                     cachedirectory: true,                     presets: ['es2015']                 }             }         ],     },     plugins: [         new webpack.noerrorsplugin()     ],     stats: {         colors: true     },     devtool: 'source-map'  }; 

it should work import 'foo/module';. resolve file ./node_modules/foo/module.js or ./node_modules/foo/module/index.js , not ./node_modules/foo/node_modules/module/index.js if expected (in case better install module via npm).


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -