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
Fix popperjs import for SvelteKit #356
Conversation
Hi, thanks. Popper was giving troubles in Sapper and svelte.repl without this though due to use of |
Related to this issue: #250 |
Two wrongs don't make a right 😄 We should fix it in popper core. I sent a PR there: floating-ui/floating-ui#1342 Sapper's deprecated at this point. In the short-term, I'd rather have it working in SvelteKit and broken in the REPL and Sapper than vice versa since SvelteKit will be the main way people will be consuming the library. Hopefully in the medium-term we can get popper.js itself fixed rather than trying to work around the issue |
Agreed popper would be great to fix, but I and other users use sapper and repl frequently and would rather not break that. I'll see if there's something we can do. I had debated forking popper as well to remove, but eh. |
Actually SvelteStrap works fine with SvelteKit now if you do import from root (a regular way), no changes needed. |
Ah thanks @vfilatov , does sveltekit not need the src imports for SSR such as sapper needed? |
After import {
Alert,
Badge,
Button,
Modal,
ModalHeader,
ModalBody,
ModalFooter
} from 'sveltestrap'; |
Ah, the example I was debugging did import from I do still think this is a good change, but I guess we can wait until popper itself is fixed In the meantime, I sent a PR to update the readme: #359 |
Bump, would love to see this merged! |
@bestguy my PR floating-ui/floating-ui#1342 was merged to fix popper-core. Could this be merged now as a result? |
looks like they reverted it floating-ui/floating-ui#1362 (would have been a breaking change) is it an option to switch to floatingui dom? edit: there's another PR trying to add export maps to popper again floating-ui/floating-ui#1526 |
It looks like it's been fixed on the main branch for an eventual v3 floating-ui/floating-ui#1502 and that floating-ui/floating-ui#1526 would backport it to 2.x Anyway, I wonder if the original reason for not merging this still applies. It was said that we wanted to prioritize Sapper over SvelteKit, but that was over a year ago. Now SvelteKit has almost 2x the usage of Sapper and so I would think that it would be better to prioritize SvelteKit over Sapper. Would that logic make sense to you @bestguy? If you're still on Sapper by chance, I'd be happy to advice on a migration to SvelteKit |
Is there any alternative or workaround that can be used before this PR get merged? Edit: I found that the fork by laxadev/sveltestrap is working fine without any errors. I install its dependencies by running |
I am experiencing the same issue with Sveltestrap. It actually prevents me from running SvelteKit. I'd really like to use bootstrap for svelte app dev. Any workarounds would be appreciated, and we really need a proper fix to this. Thanks. Cannot use import statement outside a module SyntaxError: Cannot use import statement outside a module With this package.json: { |
I use manual add {
"name": "@popperjs/core",
"type": "module", // <<<<<<<<<<<<<
"version": "2.11.5", to
|
Due to this issue bestguy/sveltestrap#356
I ran into the same issue. I use SvelteKit (1.0.0-next.338 as of writing) and my project could not start up because of the above detailed issue.
The fork suggested by @ynshung worked flawlessly for me. |
I have compiled some of the PRs opened into one + updated the dependencies (patch & minor, not major)
As proposed in another issue, we should organize ourselves to maintain an "official" fork :) |
Everyone, and @benmccann @kbsali , I really appreciate the PRs and desire to fix this for SvelteKit, but none of these fixes and forks changing to I've tried the same in past as I mentioned, but I've been unwilling to break the Svelte REPL. This is not deprecated AFAIK, and I'm a heavy user with Sveltestrap. (I know Sapper is deprecated so I wont worry about that one any longer). Upgrading to Floating UI won't fix this either, as they continue the Only solutions I can think of is:
I will gladly take any help or ideas that fixes this if it works on svelte.dev I'll see if https://github.com/Simonwep/nanopop could be used without breaking changes instead of popper. |
Ah, I hadn't realized the REPL issue. Thanks for clarifying. I've mentioned the REPL issue to the other Svelte maintainers. I'm of two minds as to whether we should makes changes there. On the one hand, there are some libraries that won't work if we don't polyfill It's not clear to me that floating-ui has rejected replacing In the meantime, usage with either the REPL or SvelteKit is impacted. I'm a bit surprised about picking the REPL over SvelteKit since many more users will be using SvelteKit. Also, there is currently a workaround implemented which hides the true issue contributing to it not being resolved yet. StackBlitz could be used for demos of this library rather than the REPL since there you have access to the Rollup config and can modify it as required. |
I'm making PRs to remove these in both Popper and Floating UI. I don't think they're worth the trouble anymore, especially since the lib is usually used transitively. |
That's great. Once floating-ui/floating-ui#2296 is merged, I can bump this PR to use the latest version of Popper, which should make this library work everywhere |
I'm surprised this is not higher priority. For me, it breaks my first attempt at using sveltestrap altogether. The "hello world" style example: <script>
import { Button } from 'sveltestrap'
</script>
<Button>a bootstrap button</Button> triggers this error. {
"name": "svelte-app",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.5.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.8.1",
"svelte": "^3.54.0",
"vite": "^4.2.0"
},
"type": "module",
"dependencies": {
"@sveltejs/adapter-static": "^2.0.1",
"bootstrap": "^5.2.3",
"sveltestrap": "^5.10.0"
}
} ps: this workaround appears to work. |
@bestguy my PR was merged to Popper and I updated this PR to use the latest version. You should be able to merge this PR now to make sveltestrap work out-of-the-box with both SvelteKit and the REPL |
Which versions in the
|
@bestguy are there any concerns you have that are keeping you from merging this? |
@bestguy @gary-mycase just checking in here again. To summarize this uses the latest popper which includes floating-ui/floating-ui#2296, so will now work out-of-the-box in both SvelteKit and the REPL |
Thanks @benmccann , let me test over weekend with a pre-release, will try and get this out asap with the 5.3 release |
Hurray! Thank you so much! |
Closes #463
Closes #474
Closes #517
This updates
@popperjs/core
to the latest version, which no longer usesprocess.env
, so it will work in the REPLImport popper the normal way. Then Vite can use the CJS version on the server-side and ESM version on the client-side. Forcing it to always be ESM breaks SSR with the latest SvelteKit. See vitejs/vite#4569 / sveltejs/kit#2161