Comments (11)
I'm going to close this issue. The original problem that I was seeing was really related to the use of console.debug
in stimulus-rails
and I've now logged a new issue there.
I'll let @glennfu open another issue in this repo if there are still problems specific to importmap-rails
and Chart.js.
from importmap-rails.
This is incredibly frustrating that is fails silently. There are a number of issues like this with importmap-rails.
from importmap-rails.
I believe this is a fundamental constraint with the browser JS engine. Not something we can do much/anything about. Cc @guybedford?
from importmap-rails.
How are you loading your stimulus controllers? lazyLoad or eagerLoad? Or you're using explicit import statements? Sounds like the latter rather than using the new default loader setup?
from importmap-rails.
I'm having this problem while using eagerLoadControllersFrom
. The Chart.js moment adapter says to add import 'chartjs-adapter-moment'
after including Chart.js. Before adding it, everything loads fine. After adding it, I see Failed to register controller: my_controller_name...
and no other explanation. I don't know how to get any clarity on what I've done wrong (I already pinned chartjs-adapter-moment in importmap). Is there a way to manually build the javascript somewhere that could provide error output?
from importmap-rails.
I started with a clean app:
rails _7.0.0_ new my_app
This already included importmap-rails
and stimulus-rails
. Then I added a route so that the application layout would be used:
# routes.rb
root "application#index"
# ApplicationController
def index
render inline: "<div data-controller='hello' />", layout: true
end
This will show the "Hello World!" text in the browser. The hello_controller.js
is imported like:
<script type="importmap" data-turbo-track="reload">{
"imports": {
...
"controllers/hello_controller": "/assets/controllers/hello_controller-24e492b6f1517d1201fffc668bb9dd12c041134bd03f35f2613ae3d68706c339.js",
"controllers": "/assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js"
}
}</script>
Then I made an invalid import
statement:
// app/javascript/controllers/hello_controller.js
import { Controller } from "bad_name_here"
The view will no longer show the "Hello World!" text and there will be no error in the JavaScript console.
I'm now seeing that this code will log an exception using console.debug
. The browser default is for these to be hidden but I can see them if I turn on "Verbose" logging. That gives me the info I'm looking for:
Failed to register controller: hello (controllers/hello_controller) TypeError: Failed to resolve module specifier "bad_name_here"...
Other areas in the Stimulus code use console.log
to log errors.
Should the console.debug
calls be flipped to console.log
? I've never had a need to turn verbose logging on, so the errors I used to see when working with Webpacker must have been logged with something like console.log
. But I'm fine with keeping verbose logging on for now if you think console.debug
is acceptable.
from importmap-rails.
Interesting I already had that turned on but it's still not giving me clarity. Good code:
import { Chart } from "chart.js"
Bad code:
import { Chart } from "chart.js"
import 'chartjs-adapter-moment'
=> stimulus-loading-685d40...883c0.js:26 Failed to register controller: chartz (controllers/chartz_controller) SyntaxError: The requested module 'chart.js' does not provide an export named 'default'
I already know that the 'chart.js' line runs fine, so why the vague error with no line number pointing to it? importmap.rb for context:
pin "chart.js", to: "https://ga.jspm.io/npm:[email protected]/dist/chart.esm.js"
pin "chartjs-adapter-moment", to: "https://ga.jspm.io/npm:[email protected]/dist/chartjs-adapter-moment.js"
from importmap-rails.
@glennfu I think you might want to try something like this:
import { Chart } from "chart.js/auto"
See: https://www.chartjs.org/docs/3.3.1/getting-started/integration.html#bundlers-webpack-rollup-etc
from importmap-rails.
That doesn't work because then importmap doesn't know what it is, since it doesn't match the string "chart.js/auto". That doc does say this is equivalent to:
import { Chart, registerables } from 'chart.js';
Chart.register(...registerables);
which also successfully loads for me, but sadly doesn't help me with my problem. Adding import 'chartjs-adapter-moment'
below still breaks the load of the controller and gives me that vague error with no line number.
It could mean that there's something wrong with chartjs-adapter-moment
that needs updating and it just simply won't work with this kind of set up. I'm not experienced enough with this kind of JS mess to know for sure, which is one of the reasons I'm eager to use some of these new JS loading libraries... so that I don't need to worry about JS loading!
from importmap-rails.
SyntaxError: The requested module 'chart.js' does not provide an export named 'default'
This error usually means you want to be using import * as Chart from 'chart.js'
or the named export from whatever module you are importing.
from importmap-rails.
I've tried import * as momentAdapter from 'chartjs-adapter-moment'
but still get the same cryptic error. Interestingly, if I try a different plugin, I can successfully add it with import zoomPlugin from 'chartjs-plugin-zoom'
. So it does seem at least in part to be a problem with that specific plugin.
I don't mean to hijack this thread with my specific issue. The only point I really want to contribute here is how I can try so many different things, and I always get the same vague error that really only tells me "something is wrong with your controller and I'm not going to tell you what it is". My hope, like the OP mentions, is that we could somehow get access to a more helpful error message.
from importmap-rails.
Related Issues (20)
- Unpin command causing net error HOT 3
- Confusing message on 'update'
- Unable to unpin HOT 1
- Persistent 404 error when pinning HOT 11
- Package works when pinned from JSPM but not when downloaded HOT 2
- Break in iOS 16.2 when upgrading from 1.2.3 to 2.0.1 HOT 4
- turbo:load event not fired anymore in test environment after upgrade from 1.2.3 to 2.0.1 HOT 3
- Feature suggestion: optional `process.env` polyfill
- Multiple importmaps HOT 6
- Importmap update removes pins via http HOT 1
- importmap pin/update removes preload: false
- ga.jspm.io never updates HOT 3
- ./bin/importmap outdated command fails with undefined method `dig' for an instance of String HOT 6
- Add option to `bin/importmap pin URL` to create direct/remote link without downloading
- Option to 're-sync' vendor folder HOT 2
- How to add jquery in importmaps rails 7 HOT 2
- `update` does not update a package even when `outdated` shows the new version HOT 1
- Some file are missing / Not included HOT 1
- Get SyntaxError: Identifier has already been declared
- @uppy/dashboard and @uppy/remote-source fail to install.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from importmap-rails.