-
Notifications
You must be signed in to change notification settings - Fork 125
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
Does not appear to work in Rails 7 using import-map (new Rails default) #113
Comments
This works as import:
But now I'm to the next error:
|
I was getting a similar error
after using |
I have the same issue...using importmaps with the downloaded file causes problem while using the CDN works perfectly. |
Ok, the problem seems to come from the js module that is bundled with this gem. The asset pipeline serves that one instead of the one in My workaround to still use importmaps and downloaded js modules was to rename the file to avoid this conflict.
import LocalTime from "local-time-cdn"
LocalTime.start() Tested in Firefox 96 and Chrome 97 Edit: |
Back to this again. Rails 7 application, using the CDN. The following code did not work:
On a hunch, I tried the following, which worked perfectly:
This uses the CDN version. 🤷🏻♂️ |
@1klap's reply hits the nail on the head. Thanks! Note that there's a way to still reference the library in JS by its original name. Just add the pin "local-time", to: "vendored-local-time.js" Then, you can: import LocalTime from "local-time"
LocalTime.start() Crucially, the vendored file needs to be renamed to something other than This won't be a problem anymore once #134 is released. |
@josefarias Thanks for addressing the problem in your recent changes. Are there plans to do a version bump? |
Hey @vietqhoang, I plan to spend my upcoming cooldown tying up loose ends in this library — including cutting a new release. So no promises, but it might happen soon. In the meantime, you can vendor the JS library (bundled versions are checked into the repo here), and you can point your Gemfile version to the main branch for the Ruby library. EDIT: I should add the disclaimer that you should test that your app works correctly while running on EDIT 2: This work didn't make the cut this last cooldown. Maybe next one. Sorry! Can't make any promises. |
With downloading the new default in importmap-rails - rails/importmap-rails#217 - I suspect people using this lib are going to bump into this issue more. Thanks for the workaround guidance! Would love to see version bump with changes, but noted on priorities. |
Could someone share up-to-date and complete instructions on how make |
@marckohlbrugge, are you using the latest This does it for me: ❯ rails new test_app
❯ cd test_app
❯ git add .
❯ git commit -m "Initial commit"
❯ bin/importmap pin local-time
#=> Pinning "local-time" to vendor/javascript/local-time.js via download from https://ga.jspm.io/npm:local-time@2.1.0/app/assets/javascripts/local-time.js
❯ mv vendor/javascript/local-time.js vendor/javascript/vendored-local-time.js
❯ sed -i '' '$ s/pin "local-time" # @2.1.0/pin "local-time", to: "vendored-local-time.js" # @2.1.0/' ./config/importmap.rb
❯ git add .
❯ git diff --cached Results in: diff --git a/config/importmap.rb b/config/importmap.rb
index bc060ed..a3aa833 100644
--- a/config/importmap.rb
+++ b/config/importmap.rb
@@ -5,3 +5,4 @@ pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
+pin "local-time", to: "vendored-local-time.js" # @2.1.0
diff --git a/vendor/javascript/vendored-local-time.js b/vendor/javascript/vendored-local-time.js
new file mode 100644
index 0000000..bd59480
--- /dev/null
+++ b/vendor/javascript/vendored-local-time.js
@@ -0,0 +1,2 @@
+var r="undefined"!==typeof globalThis?globalThis:"undefined"!==type [truncated...] The readme should take you the rest of the way. Note that renaming the vendored file and editing |
I've using the latest version of
Tried on a fresh Rails app and have the same result.
Relevant: rails/importmap-rails#231 |
Managed to replicate, no clue why it was working for me yesterday 🤷🏻♂️ Passing ❯ bin/importmap pin local-time
#=> Couldn't find any packages in ["local-time"] on jspm
❯ bin/importmap pin local-time --from=jspm.io
#=> Pinning "local-time" to vendor/javascript/local-time.js via download from https://ga.jspm.io/npm:local-time@2.1.0/app/assets/javascripts/local-time.js Looks like a breaking change in the jspm API. Made a PR to fix in |
I've just released the newest version. This should now work without having to rename anything. So: ❯ rails new test_app
❯ cd test_app
❯ bundle add local_time
❯ bundle install
❯ bin/importmap pin local-time # works now per https://github.com/rails/importmap-rails/pull/234#issuecomment-1892668735
#=> Pinning "local-time" to vendor/javascript/local-time.js via download from https://ga.jspm.io/npm:local-time@3.0.2/app/assets/javascripts/local-time.es2017-esm.js Then follow the readme to import and start the library. Let me know if you run into trouble, preferably creating a new issue if unrelated to this one. |
Thanks for quick turnaround -- works as expected after version bump. |
Howdy, I'm building an app from scratch in Rails 7 Alpha. This uses import maps.
In the import map, I have
pin "helpers/local-time"
, which works as expected. I can import the file no problem. I import thusly:I get the following error:
I know that's in the Shim, not in local time, but the error traces to the following location. I'm not a JS guy, so not quite sure how to correct in
The text was updated successfully, but these errors were encountered: