Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM/CJS conflict when importing Sveltestrap components #562

Open
MattPhantastic opened this issue Jul 29, 2023 · 4 comments · Fixed by #566
Open

ESM/CJS conflict when importing Sveltestrap components #562

MattPhantastic opened this issue Jul 29, 2023 · 4 comments · Fixed by #566

Comments

@MattPhantastic
Copy link

MattPhantastic commented Jul 29, 2023

I have created a SvelteKit project using pnpm create svelte

Recently I ran a pnpm update. Now, whenever I import Sveltestrap components, my site crashes and says there's a conflict between ESM and CJS.

[vite] Error when evaluating SSR module /src/routes/(logged out)/signup/+page.svelte: failed to import "/node_modules/.pnpm/[email protected][email protected]/node_modules/sveltestrap/src/index.js"
|- /Users/.../node_modules/.pnpm/@[email protected]/node_modules/@popperjs/core/dist/esm/popper.js:1
import { popperGenerator, detectOverflow } from "./createPopper.js";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1048:15)
    at Module._compile (node:internal/modules/cjs/loader:1083:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Module._load (node:internal/modules/cjs/loader:838:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:527:24)

Internal server error: Cannot use import statement outside a module
      at Object.compileFunction (node:vm:360:18)
      at wrapSafe (node:internal/modules/cjs/loader:1048:15)
      at Module._compile (node:internal/modules/cjs/loader:1083:27)
      at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
      at Module.load (node:internal/modules/cjs/loader:997:32)
      at Module._load (node:internal/modules/cjs/loader:838:12)
      at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
      at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
      at async Promise.all (index 0)
      at async ESMLoader.import (node:internal/modules/esm/loader:527:24)

I also noticed when running pnpm install sveltestrap that the peer Svelte version is unmet:

Already up to date
Progress: resolved 242, reused 221, downloaded 0, added 0, done
 WARN  Issues with peer dependencies found
.
└─┬ sveltestrap 5.10.0
  └── ✕ unmet peer svelte@^3.29.0: found 4.1.1

Is Sveltestrap not yet compatible with Svelte 4? — How soon can this issue be resolved?


EDIT: I tried downgrading.

First I tried pnpm install [email protected]:

Packages: +11 -25
+++++++++++-------------------------
Progress: resolved 228, reused 206, downloaded 1, added 11, done
node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/svelte-preprocess: Running postinstall script, done in 78ms
node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit: Running postinstall script, done in 2.6s

devDependencies:
- svelte 4.1.1
+ svelte 3.29.0 (4.1.1 is available)

 WARN  Issues with peer dependencies found
.
├─┬ @sveltejs/kit 1.22.3
│ ├── ✕ unmet peer svelte@"^3.54.0 || ^4.0.0-next.0": found 3.29.0
│ └─┬ @sveltejs/vite-plugin-svelte 2.4.3
│   ├── ✕ unmet peer svelte@"^3.54.0 || ^4.0.0": found 3.29.0
│   └─┬ @sveltejs/vite-plugin-svelte-inspector 1.0.3
│     └── ✕ unmet peer svelte@"^3.54.0 || ^4.0.0": found 3.29.0
├─┬ eslint-plugin-svelte 2.32.4
│ ├── ✕ unmet peer svelte@"^3.37.0 || ^4.0.0": found 3.29.0
│ └─┬ svelte-eslint-parser 0.32.2
│   └── ✕ unmet peer svelte@"^3.37.0 || ^4.0.0": found 3.29.0
└─┬ svelte-check 3.4.6
  └── ✕ unmet peer svelte@"^3.55.0 || ^4.0.0-next.0 || ^4.0.0": found 3.29.0

Done in 10.8s

Then I realised how many other dependencies I also had to also downgrade, and so I decided to just try pnpm install [email protected]:

Packages: +11 -11
+++++++++++-----------
Progress: resolved 228, reused 206, downloaded 1, added 11, done
node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/svelte-preprocess: Running postinstall script, done in 100ms
node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit: Running postinstall script, done in 3.1s

devDependencies:
- svelte 3.29.0
+ svelte 3.55.0 (4.1.1 is available)

Done in 11.2s

Nothing seemed 'unmet' this time. Yet the site still crashes with the same ESM/CJS conflict. What gives?

@MattPhantastic
Copy link
Author

I have recently discovered that this issue has already been heavily discussed in other threads. Feel free to just delete this thread if you see it… I'll follow the existing threads. 😅

@bestguy
Copy link
Owner

bestguy commented Aug 6, 2023

Hi @MattPhantastic please try with latest release (5.11.1) and let me know if you still see issues. Please close if resolved.

@benmccann
Copy link
Contributor

It is broken on 5.11.1, but I've sent a fix: #566

@bestguy
Copy link
Owner

bestguy commented Aug 31, 2023

Hi folks, please confirm this is resolved with v5.11.2

@bestguy bestguy reopened this Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants