Closed soullivaneuh closed 4 years ago
I also try to use @rollup/plugin-commonjs
:
diff --git a/rollup.config.js b/rollup.config.js
index 18346f6..3716934 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -1,5 +1,6 @@
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
+import commonjs from '@rollup/plugin-commonjs';
import pkg from './package.json';
const preprocess = require('./preprocess');
@@ -25,5 +26,6 @@ export default {
plugins: [
svelte({ preprocess }),
resolve(),
+ commonjs(),
],
};
But this results to on error:
> rollup --exports named -c
src/index.js → dist/index.mjs, dist/index.js...
[!] TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at new MagicString (/home/sullivan/p/gitlab.com/nexylan/ui/node_modules/rollup/dist/shared/node-entry.js:477:37)
at Module.setSource (/home/sullivan/p/gitlab.com/nexylan/ui/node_modules/rollup/dist/shared/node-entry.js:10087:28)
at /home/sullivan/p/gitlab.com/nexylan/ui/node_modules/rollup/dist/shared/node-entry.js:12366:20
at async Promise.all (index 0)
at async Promise.all (index 0)
at async Promise.all (index 0)
There might be a Rollup plugin or configuration that turns require()
s into import
s, but this would be unrelated to Svelte.
As a general rule, I would suggest writing your components with ESM import
s and have them compile to require
s where necessary for use on the server.
Also, on its own, Rollup ignores require
statements altogether.
So Svelte is forwarding require('gravatar')
to Rollup, which purposefully does nothing to it.
There might be a Rollup plugin or configuration that turns require()s into imports, but this would be unrelated to Svelte.
Was not sure, this is why I opened here.
Also, on its own, Rollup ignores require statements altogether.
So there is no way to make it working with rollup at all? :thinking:
As a general rule, I would suggest writing your components with ESM imports and have them compile to requires where necessary for use on the server.
@Conduitry I'm quite new here, I am not sure about what your are telling me to do. :thinking:
You should do import gravatar from 'gravatar'
This is maybe a bad configuration issue, but I didn't find any useful help on my search.
I have a
Nav.svelte
component usinggravatar
:This component is exported onto a npm package created from this template months ago. Here is the current Rollup configuration:
The compilation "works" but just put a require on the
index.mjs
file:Resulting on a browser error:
I don't know how to resolve this issue. Is this referenced somewhere on the official documentation? :thinking:
Thanks