rollup cannot find exported function using commonjs plugin even with namedExports

1.6k views Asked by At

I'm trying to use rxdb with rollup but rxdb imports the clone module, and apparently in a way incompatible with rollup and the commonjs plugin.

I see this error when I run yarn dev:

[!] Error: 'default' is not exported by node_modules/clone/clone.js, imported by node_modules/rxdb/dist/es/util.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/rxdb/dist/es/util.js (6:9)
4:  */
5: import randomToken from 'random-token';
6: import { default as deepClone } from 'clone';
            ^
7: /**
8:  * Returns an error that indicates that a plugin is missing
Error: 'default' is not exported by node_modules/clone/clone.js, imported by node_modules/rxdb/dist/es/util.js
    at error (/home/chrisdawson/xxx/svelte/node_modules/rollup/dist/shared/rollup.js:5305:30)

I thought namedExports in the rollup/commonjs plugin could fix this, but I am unsure how to use it. This is a snippet from my rollup.config.js file:

commonjs({
  namedExports: { 'node_modules/clone/clone.js': [ clone ]},
}),

The end of the clone.js file looks like this:

chrisdawson@pop-os:~/svelte$ cat node_modules/clone/clone.js 
...
return clone;
})();

if (typeof module === 'object' && module.exports) {
  module.exports = clone;
}

What is the correct way to permit import of this "default" export?

My package dependencies for rollup are:

"rollup": "^2.3.4",
    "rollup-plugin-commonjs": "^10.1.0",
    "rollup-plugin-css-only": "^3.1.0",
    "rollup-plugin-livereload": "^2.0.0",
    "rollup-plugin-node-polyfills": "^0.2.1",
    "rollup-plugin-node-resolve": "^5.2.0",
    "rollup-plugin-postcss": "^4.0.0",
    "rollup-plugin-svelte": "^7.1.0",
    "rollup-plugin-terser": "^7.0.0",

0

There are 0 answers