Rollup replaces node modules imports with relative paths

Viewed 3288

I'm having a problem with Rollup and the rollup-plugin-node-resolve.

If I have an import of this kind:

import _ from 'lodash';

it gets converted to:

import _ from '../node_modules/lodash/lib/index.js';

This breaks the bundle when I try to use it inside a project which uses Webpack because the node_modules folder is not child of the folder of my Rollup-bundled package obviously (because npm flats the dependencies).

I am already defining all the node_modules as external.

This is my relevant config:

{
  entry: 'dist/components-index.js',
  external: id => id.indexOf('node_modules') >= 0,
  plugins: [
    resolve({
      extensions: ['.jsx', '.js', '.json'],
    }),
    commonjs({
      namedExports: { '../xxx-styles/lib/index.js': ['common', 'dark', 'light' ] },
    }),
  ],
}

How can I make the build keep the node modules import preserve the absolute paths? I'd like to keep them as I write, so that node.js/webpack/wathever can resolve the imports properly.

1 Answers
Related