1

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",

xrd
  • 4,019
  • 6
  • 30
  • 39
  • I think you should be able to remove the `namedExports` configuration and just do `import deepClone from 'clone';`. – Felix Kling Apr 27 '21 at 07:23
  • Unfortunately, that is not happening in my code. rxdb is using that line of code, and I'm not sure I want to patch that to make it work. You can see that is inside a node_modules JS file. – xrd Apr 27 '21 at 07:29
  • 1
    Ah sorry, I missed that. So you are getting that error already without the `namedExports` config? – Felix Kling Apr 27 '21 at 07:30
  • 1
    It might be worth creating a test file that imports `clone` in a couple of different ways just to see what rollup compiles it into. – Felix Kling Apr 27 '21 at 07:35
  • Good ideas. Yes, the error is there whether I have namedExports as an option or not. I'll try your suggestions. – xrd Apr 27 '21 at 07:38
  • @xrd did you fix this ? have a similar issue: https://github.com/FredKSchott/rollup-plugin-polyfill-node/issues/38#issuecomment-1007414843 – Syffys Jan 07 '22 at 13:49

0 Answers0