How can I prevent rollup from leaving an import statement to a external library in the bundle?

Viewed 627

I have such web app:

  • typescript code
  • rollup as bundler
  • mapboxgl as an external library
  • use es6 modules
  • produce a single bundle.js holding all typescript files but not the mapboxgl code which is referenced with a separate script tag

All is fine, the only problem is that the bundle.js includes a wrong

import { Map } from 'mapbox-gl';
// why is this import here, although rollup.config declares mapbox-gl external?

... bundle code follows as expected

at its head.

rollup.config.js:

export default {
    input: './js/app.tsx',
    output: [
        {
            file: 'dist/bundle.js',
            format: 'es'
        },
    ],
    external: ['mapbox-gl'], // this should prevent imports from mapbox-gl in the bundle
    plugins: [
        typescript()
    ],
}

I searched all stackoverflow and through endless github repos but that did not reveal why this import statement is left. I opened a feature request in rollup to allow plain js bundle creation, as I believe that rollup is correct as it assumed that the bundle is used as a module - for format is set to "es" in the end.

https://github.com/rollup/rollup/issues/3868

0 Answers
Related