sveltejs / rollup-plugin-svelte

Compile Svelte components with Rollup
MIT License
505 stars 79 forks source link

Incompatibility with Node.js 14 ESM exports. #184

Closed kriskowal closed 3 years ago

kriskowal commented 3 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch rollup-plugin-svelte@5.2.3 for the project I'm working on.

The problem is that svelte has an exports map in its package.json that expresses that svelte/compiler corresponds to svelte/compiler.mjs and does not also provide a svelte/compiler.js mapping. rollup-plugin-svelte takes a dependency on the latter, depending on the Node.js version.

Here is the diff that solved my problem:

diff --git a/node_modules/rollup-plugin-svelte/index.js b/node_modules/rollup-plugin-svelte/index.js
index 0d52cfb..07bbeea 100644
--- a/node_modules/rollup-plugin-svelte/index.js
+++ b/node_modules/rollup-plugin-svelte/index.js
@@ -8,7 +8,7 @@ const { encode, decode } = require('sourcemap-codec');
 const major_version = +version[0];

 const { compile, preprocess } = major_version >= 3
-   ? require('svelte/compiler.js')
+   ? require('svelte/compiler')
    : require('svelte');

 function sanitize(input) {

This issue body was partially generated by patch-package.

bluwy commented 3 years ago

Duplicate of https://github.com/sveltejs/rollup-plugin-svelte/issues/152

The latest version of rollup-plugin-svelte should fix this.