I'm working on an old project at work and it seems to be using rollup.js to bundle.
I'd like to use sanitize-html plugin to change some input, but I get the error that default is not exported:
[ERROR] Error: 'default' is not exported by src/path/node_modules/sanitize-html/index.js, imported by src/path/src/iql-editor/iql-editor.js
[ERROR] at error (path/node_modules/rollup/dist/shared/rollup.js:158:30)
[ERROR] at Module.error (path/node_modules/rollup/dist/shared/rollup.js:12382:16)
[ERROR] at Module.traceVariable (path/node_modules/rollup/dist/shared/rollup.js:12767:29)
[ERROR] at ModuleScope.findVariable (path/node_modules/rollup/dist/shared/rollup.js:11559:39)
[ERROR] at ReturnValueScope.findVariable (path/node_modules/rollup/dist/shared/rollup.js:6930:38)
I did try a couple thing, first I added the dependency in the local package.json:
"dependencies": {
"popper.js": "^1.14.3",
"sanitize-html": "^2.3.3"
},
And I updated the rollup.config.js file like this:
const path = require('path');
import { babel } from '@rollup/plugin-babel';
import { nodeResolve } from '@rollup/plugin-node-resolve';
const BUNDLE = process.env.BUNDLE === 'true';
const FORMAT = process.env.FORMAT || 'iife';
const destDirectory = '../dist/js/';
let destFile = %path%;
const external = ['popper.js', 'sanitize-html'];
const plugins = [
babel({
exclude: 'node_modules/**', // only transpile our source code
}),
];
const globals = {
'popper.js': 'Popper',
'sanitize-html': 'sanitizeHtml',
};
if (BUNDLE) {
destFile = %path%;
// remove last entry in external array to bundle Popper
external.pop();
delete globals['popper.js'];
delete globals['sanitize-html'];
plugins.push(nodeResolve());
}
module.exports = {
input: path.resolve(__dirname, '../%path%'),
output: {
file: path.resolve(__dirname, `${destDirectory}${destFile}`),
format: FORMAT,
banner: `banner`,
name: 'name',
globals,
},
external,
plugins,
};
The popper extension was already present, so I followed the same logic.
In my working file, I'm using the html-sanitize plugin this way:
import Popper from 'popper.js';
import sanitizeHtml from 'sanitize-html';
...
const anyName = (() => {
this.doSomething(
elt.value,
sanitizeHtml(elt.displayValue),
word,
elt.type
)
});
What am I doing wrong?