Questions tagged [import-maps]

Import maps allow control over the resolution of bare import specifiers (e.g., import x from "x"). They define what URLs get fetched by JavaScript import statements and import() expressions.

Import maps allow control over the resolution of bare import specifiers (such as import x from "x"). They define what URLs get fetched by JavaScript import statements and import() expressions.

132 questions
26
votes
4 answers

How to add custom JS file to new rails 7 project

I created new rails 7 project rails new my_project and have a problem to include my custom JS file to be processed by rails. my "javascript/application.js" import "@hotwired/turbo-rails" import "controllers" import "chartkick" import…
pa3k
  • 501
  • 1
  • 4
  • 8
9
votes
1 answer

Rails 7 and Import-map and loading custom JS file

I am trying to load my custom js. but getting errors. Error is following. Failed to register controller: notification (controllers/notification_controller) Error: Unable to resolve specifier '@noty' imported from…
Jin Lim
  • 1,759
  • 20
  • 24
9
votes
1 answer

Use Import Maps and Stimulus with Rails 6

I'm currently on Rails 6.0.4 and I want to use Stimulus to build a new page. There's a lot of work still to do before upgrading to Rails 7, so I want to use importmaps and stimulus with Rails 6 if possible. But so far I haven't been able to get a…
9
votes
2 answers

How to set up importmap-rails in Rails 7 engine?

I have opened an issue in the importmap-rails gem github repository here about this but thought I'd throw the question out here in case anyone might have a workaround This is what I have discovered so far A new engine with Rails 7 alpha 2 or Rails…
jamesc
  • 12,423
  • 15
  • 74
  • 113
8
votes
1 answer

Rails 7 Importmap Bootstrap

So, I've set up my rails 7 application by doing the following. rails new . To add bootstrap I've implemented it with importmap (no webpacker) as following ./bin/importmap pin bootstrap which loaded these lines (I added the preload: true) pin…
8
votes
2 answers

Rails 7 Import Maps - import folder with custom scripts

playing around with Rails 7 and import maps. Trying to import a folder with some custom JS. # config/importmap.rb pin_all_from "app/javascript/custom", under: "custom" # app/javascript/application.js import "custom" Gives Uncaught TypeError:…
Phil-6
  • 552
  • 6
  • 16
7
votes
1 answer

Import Maps not using precompiled JavaScript assets in pipeline in production environment only (Rails 7)

Anyone managed to wrap their head around importmaps in Rails 7? I have a headscratcher. If I run ./bin/importmap json in development, I get this (as expected): { "imports": { "application":…
g_t_m
  • 704
  • 4
  • 9
7
votes
4 answers

How can I install jQuery in Rails 7 with importmap?

I have a new Rails 7 application. I'm currently trying to learn all the new features since Rails 5. I want to use the following code in my javascript file, but so far I'm getting the following error: Uncaught ReferenceError: $ is not…
daveomcd
  • 6,367
  • 14
  • 83
  • 137
7
votes
2 answers

Rails 7 Importmap Pins incompatible Jquery source

Question Why does the source generated by the importmaps command not work with Bootstrap 4.6.1 but a modified source for the same version of jquery work? Problem Details I created a rails 7 app using importmaps to manage the javascript. I am pinning…
Joe Thor
  • 1,164
  • 1
  • 11
  • 19
6
votes
1 answer

In Rails 7 can one use import maps along with a js bundling solution or are they exclusive?

I'm starting to get my head around the new import maps functionality in rails 7. It seems there are a lot of advantages of using this functionality. It seems however if I need a transpile step (eg JSX) that I need a js bundling solution. It's not…
pixelearth
  • 13,674
  • 10
  • 62
  • 110
6
votes
0 answers

Rails 7 import map with javascript package from cdn throwing CORS error

I'm trying to import a JS package hosted on a CDN using the new Rails 7 import maps feature. However, whenever my Rails project loads I get a CORS related error in this form: Access to script at 'https://cdn.vender-application.com/package.js' from…
James
  • 1,158
  • 4
  • 13
  • 23
6
votes
1 answer

Rails 7 (7.0.2.3) Importmap jQuery is not defined in view

I've looked around for as much help as possible regarding installing jQuery in Rails 7 (7.0.2.3). I want to use it in script tags in my views, but I can't seem to get it exported to where it is globally available, er...ANYWHERE for that…
user1572597
  • 373
  • 3
  • 15
6
votes
3 answers

Where to place Javascript used in one page only in Rails 7 with importmap

When using Rails 7 with import maps, where do I put code that should be executed by one view only? Specifically, I have a view that needs to run some Javascript code on load. My Javascript looks something like this: import {TheController} from…
Zack
  • 6,232
  • 8
  • 38
  • 68
6
votes
2 answers

How access JS function using Import Maps in Ruby On Rails 7?

I'm newbie to JS modules and Import Map, now I'm using Ruby on Rails 7 and I couldn't find a way to get this working: Js Module (proposals.js): function openProposalMirror() ... application.js import * as Proposal from "./proposals.js" On the…
Gedean Dias
  • 1,063
  • 1
  • 10
  • 24
6
votes
2 answers

404 errors on javascript when using importmaps in Rails 7 in production

I'm not sure if this is an importmaps issue or something else, but in Rails 7.0.0.alpha2, I'm getting 404 errors on the javascript files. Wondering if I'm missing some sort of production "compile" step as it works fine in development. #…
Shpigford
  • 24,748
  • 58
  • 163
  • 252
1
2 3
8 9