-
Notifications
You must be signed in to change notification settings - Fork 120
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
Popper.js not working when --download is used #65
Comments
Did you try manually pinning popperjs/core --download ? |
Or does it show up in your importmap? |
I unpinned and pinned only popper with |
cc @guybedford |
For packages that require multiple files present in a package structure, what is needed is to download all of the files of the package, and locate the mappings to the local folder. So I think there are two problems:
For (1), the list of files of a package on JSPM can be iterated by reading the package.json "files" array which is always resolved to a flat array of files that can be fetched. So download logic could be updated to handle this case. Alternatively it would be possible to restrict the workflows to single file modules only, or at least have a clear warning when non-single-file modules are loaded. But I think folder packages will ultimately need to be supported at some point. |
Ah, yes, I had totally forgotten about this with multiple files. I remember we talked about it. I'll try to have a swing at amending the bin/importmap to deal with this case. |
@guybedford Trying to look into this now, and not quite sure how to detect the multi-file modules. I thought I could just compare the count of staticDeps to map/imports, but that doesn't seem like the case. Does this require an extension on the API side of JSPM? |
@dhh would it work if we upgraded I've posted an issue for an approach in jspm/generator#91, if that sounds like the right sort of thing I can update the API appropriately. |
Actually thinking about this further, I think a more high-level checkout API would be needed for this sort of thing. I've posted a concept in jspm/generator#92. Update: Instead a simple graph API is available for generation when using the graph option, outputting the dependency trace grouped by package boundaries, which should give all the info necessary to achieve any requirements here. |
I think there is still an issue even when the import { Tooltip } from 'bootstrap'
new Tooltip(my_element) This works when my app is using Webpacker. If I switch to # config/importmap.rb
pin "bootstrap", to: "https://ga.jspm.io/npm:[email protected]/dist/js/bootstrap.esm.js"
pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/[email protected]/lib/index.js" The page will load without any of the
The code down in // config/webpack/development.js
process.env.NODE_ENV = process.env.NODE_ENV || 'development' |
@chadrschroeder |
Note as a quick fix you can also define it - |
It looks like maybe this is really an issue with the URL provided by JSPM.org. When I use their Online Import Map Generator and I have "Browser" checked and "Node" unchecked, then I also see the But the distribution targets documentation for Popper V2 says:
Here's a minimal example of an HTML document that uses some of the elements in the Popper.js tutorial. <html>
<head>
<script type="importmap">{
"imports": {
"@popperjs/core": "https://ga.jspm.io/npm:@popperjs/[email protected]/lib/index.js"
}
}</script>
<script type="module">
import { createPopper } from "@popperjs/core";
const button = document.querySelector("#button");
const tooltip = document.querySelector("#tooltip");
createPopper(button, tooltip);
</script>
</head>
<body>
<button id="button" aria-describedby="tooltip">My button</button>
<div id="tooltip" role="tooltip">My tooltip</div>
</body>
</html> The full tooltip behavior isn't implemented in this example but it illustrates the problem. When the URL is:
then the
then the I'm going to post an issue to Popper.js to see if they can do something so that JSPM.org provides the correct URL. |
Can confirm modifying my |
I also encounter 404 not found as described in the OP when using pin "swiper" # @7.4.1
pin "dom7" # @4.0.4
pin "ssr-window" # @4.0.2 And three files are downloaded to However export{A as A11y,d as Autoplay,C as Controller,k as EffectCards,i as EffectCoverflow,j as EffectCreative,g as EffectCube,E as EffectFade,h as EffectFlip,f as FreeMode,G as Grid,c as HashNavigation,H as History,K as Keyboard,L as Lazy,e as Manipulation,M as Mousewheel,N as Navigation,P as Pagination,b as Parallax,a as Scrollbar,S as Swiper,T as Thumbs,V as Virtual,Z as Zoom,S as default}from"./_/6811b57d.js";import"ssr-window";import"dom7"; So it wants to import JS from a file A workaround is to either avoid the |
Hey man, you can just copy code from https://unpkg.com/browse/[email protected]/swiper-bundle.js to your |
My solution for this problem is: Going to bootstrap doc, download the file directly on CDN then, put it into
In the
Then import them normally, in
|
Would be nice perhaps with an FAQ about how to resolve particular packages that don't just work out of the box. If anyone wants to explore that, please open a PR for it. |
@darkamenosa i basically did the same, just manually vendor the esm from the cdn. I just bumped bootstrap to 5.2 with These things are always easy to resolve, but can be confusing with all the unrelated noise. It's nice seeing utilities like https://www.jsdelivr.com/esm been using it for quick isolated inline sanity checks on the fly |
…ivr+esm (weaverryan, nicolas-grekas) This PR was merged into the 6.3 branch. Discussion ---------- [AssetMapper] Change default importmap "provider" to JsDelivr+esm | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | yes | Deprecations? | no | Tickets | None | License | MIT | Doc PR |Still TODO We currently use the https://jspm.org/ API in `importmap:require` to find a CDN URL for an npm package - just like Rails. Unfortunately, this is NOT as robust as we had thought. For me, it's broken. 3 big issues: A) **Not Combined** Some packages are not packed/combined. Example: [chart.js/auto](https://ga.jspm.io/npm:[email protected]/auto/auto.js) imports other packages and results in 3 requests instead of 1. Not TERRIBLE... so here IS a terrible example: [`@popperjs`/core](https://ga.jspm.io/npm:`@popperjs`/[email protected]/lib/index.js) (needed by `bootstrap`) results in nearly 50 requests ❗ B) **Downloading Broken** For some packages, downloading simply doesn't work - rails/importmap-rails#65. ``@popperjs`/core` is another good example. Many of its imports have the form `import"./utils/getOppositeVariationPlacement.js`. If we download the main file, it looks locally for that `utils/` file, which won't be there. [`@chart`.js/auto](https://ga.jspm.io/npm:[email protected]/auto/auto.js) is another example. C) **process.env.NODE_ENV included** Some packages (yes, again ``@popperjs`/core` is a great example!) contain `process.env.NODE_ENV` inside - rails/importmap-rails#65 (comment) I believe that some package advertise an "esm" package... but just don't do a good job of creating it... or create it without the browser context in mind (or at least in a way that's inconvenient for downloading). ### jsDelivr to the rescue THANKFULLY, jsDelivr seems to have a fantastic API/hosting that is *almost* exactly what we want: https://www.jsdelivr.com/?docs=esm They deliver fully "packaged" modules, where the only import is for peer dependencies - e.g. https://cdn.jsdelivr.net/npm/[email protected]/+esm There IS still an issue when downloading. "Peer imports" are relative -e.g. `import*as t from"/npm/`@popperjs`/[email protected]/+esm";` However, these imports follow a VERY strict pattern. So, when `--download` is passed, we parse these, download the peer dependency and update the import contents to ``@popperjs`/core`, which works with the importmap. It's not ideal that we need to do that, but it's straightforward and works great. Sorry again for this late PR - I had assumed that jspm was robust because Rails is using it. It turns out it's robust... unless you hit a "bad" package, then it's terrible. And they're not that rare: on ux.symfony.com, I have hit several. Thanks! Commits ------- b530dc3 [AssetMapper] Fix wiring resolvers, send requests in parallel and use readonly properties in MappedAsset de44614 [AssetMapper] Change default importmap "provider" to JsDelivr+esm
It's been a year and half now. Just to be clear: So no dependency management, version control, or way to easily keep dependencies updated? Also, according to the official Popper docs:
There needs to be a better way. |
In the meantime, here's the exact workaround I used, for future readers. This PR from the Symfony team found that JsDelivr's ESM mode was much better at packaging dependencies than JSPM. Symfony has accordingly migrated their ImportMap implementation to use JsDelivr instead. However, when I tried running The solution I landed on was:
Finally, I ran into the <!-- In app/views/layouts/application.html.erb -->
<script>
window.process = { env: { NODE_ENV: 'production'} }
</script> That did the trick for now. If |
Just FYI, the process can be simplified by doing the following:
The command maps to the desired nested esm file. Running it returns the following message.
And the following pin line will be added to
The pin can now be referenced by The reference can be manually updated if For example, the pin reference can be updated back to the following:
I leave the |
Wow, thanks @vietqhoang! This now works perfectly for me with 1. Pin from JSDelivr./bin/importmap pin @popperjs/core@latest/+esm --download --from jsdelivr 2. Add the fix for
|
Need change
to
And manually change the file name in vender. Seems '+' is not legal in url path. |
FYI, the popper project has changed it's name to floating-ui, and at least for popper v2, they don't recommend "direct download". "Managing dependencies by 'directly downloading' them and placing them into your source code is not recommended for a variety of reasons, including missing out on feat/fix updates easily. Please use a versioning management system like a CDN or npm/Yarn." |
no |
Also that doesn't make any sense, i'm literally using version control and a cdn. "CDN or NPM" is a wild statement to put in their README. We should be applying upstream pressure on maintainers of DOM manipulating libraries to distribute javascript for web browsers. Updated 2024 version with importmap-rails >2
bin/importmap pin @popperjs/[email protected]/+esm --from jsdelivr
mv vendor/javascript/@popperjs--core--+esm.js vendor/javascript/stupid-popper-lib-2024.js # config/importmap.rb
pin "@popperjs/core", to: "stupid-popper-lib-2024.js" |
I apologize in advance if this is not a importmap problem, I am still learning to use it.
I have problem with bootstrap configuration through importmaps, for some reason when I run
bin/importmap pin bootstrap --download
I am getting these errors in chrome console (jsdelivr, unpkg) cdn providerswhen I use command without download option like this
bin/importmap pin bootstrap
it works properly...not sure what is the problem in both commands it uses same cdn linkerrors below are from JSPM cdn provider
javascript/application.js
config/importmap.rb
The text was updated successfully, but these errors were encountered: