-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
require.js added to global namespace, when serving via dartdevc #33979
Comments
/cc @natebosch and @jakemac53 if this should be a build issue instead. |
I think DDC is the right place to track this for now. I know DDC supports other strategies than require.js and switching to one of those would be a build issue, so if we decide that's the right course of action we can move the issue over. |
Thanks Nate! |
I've got similar case. My Electron app loads dart webapp written in dart with node integration enabled to enable intercommunication between dart and electron apps. Obviously Node @natebosch can you elaborate more on "other strategies than require.js"? Are they user-configurable? |
As of today, no, using anything other than require.js is not an option with The |
I wanted to lazily load third-party libs but most of them uses requirejs and didn't work because of this. |
@jmesserly wdyt about adding some optional argument which is a global namespace to look for require/define in? Essentially we could pass in |
There is also this FAQ https://requirejs.org/docs/faq-advanced.html#rename which says not to do this explicitly though, but the reasoning may not apply in our case. |
That sounds quite reasonable to me. |
@jakemac53 , I'd like to add couple of examples. As you can see in
This means, that right now we need to use this libraries differently in production (with no defined window.define method), and in developer environment (with requirejs from ddc, which defines window.define method). |
This seems like a good solution. What also might make sense is "scoping" requirejs where only DDC-compiled programs can access it. |
I'm hitting this issue while trying to dynamically load |
I would be one of the users that would argue for it or something equivalent (see the issue referenced above). Now that Flutter Web is here and plugins are getting web support, many of those would need to load their related JS libraries. The fact that it is readily available in debug mode (visible in Chrome console among the sources) makes us believe that this is something intentional and also that being stripped in release mode is just a bug. If you decide on another loader, no problem, as long as it's compatible with the usual library formats like UMD and others. But don't remove or hide that capability on purpose now that Flutter Web is finally a reality. |
It is not intentional and we don't plan on add any module loader on production mode. Trying to fit into other modular JS apps is non-goal. Our most likely resolution will be to stop using require.js at all, even in dev mode. |
Note that using a format which is compatible with typical module formats is also a non-goal at this time. We just happened to use one because it was well defined and easy to use. However, we have already hit several limitations and its likely we will do something custom in the future that allows for a better dev experience, such as reloading individual modules in the heirarchy without reloading all parents of that module. |
With CanvaskKit, there is an even bigger problem:
This practically makes it impossible to use a |
Just chiming in on this one - this impacts FlutterFire development as we're unable to directly pull in the Firebase SDK programatically, instead they have to be loaded via the CDN within the |
@Ehesp As mentioned in flutter/flutter#58428, all it would take is to add a single module ID to the JS. I haven't been able to even trigger a response so far. :-) |
@ditman Run into this issue while reviewing our issues with most comments. Is it still relevant for flutter to fix? If yes, what is is the priority here? |
@annagrin yes, I think this is still relevant. In addition to the stuff mentioned above, requireJS does not support TrustedTypes (and probably will never do), so Flutter can't use TrustedTypes in development mode. I'm not sure about the priority of this, and I am also not sure of the ownership (it's probably shared :P). I know flutter configures requireJS here, but I think DDC is generating the requireJS modules when compiling in debug mode? IMO, |
Fwiw, I don't know how much flutter uses it, but in build_web_compilers we do use a fair number of features from require.js that would not be available with standard ES6 modules. We can intercept errors for failed modules, as well as modify the paths for where to actually look up modules, customize timeouts, etc. Doesn't mean we couldn't migrate to ES6 modules though, but it would be a fair bit of work and we would lose a few nice to have features. |
Ah, thanks for the extra context @jakemac53; the only thing I see from the Flutter side is the module loading AFAIK. |
Oh another topic for this is hot reload/restart. I don't know if you can achieve that with es6 modules... past support always used custom require.js hooks to reload specific modules, or similar support in our custom module loader. |
require.js is EoL'd, but not even the maintainer knows what to recommend in its place. |
have we ever sketched out how much effort it would take to migrate to the internal module strategy in build_web_compilers? Would it require SDK changes? |
I think it would be a fair chunk of work, plus rolling it out may be challenging because there may be assumptions in webdev and/or dwds that would have to be resolved. |
Fwiw, instead of changing build_web_compilers I would probably just jump straight to using frontend_server. |
Related: #52361 |
One more: flutter/flutter#126131 |
This is one for discussion, I think.
While migrating to Dart2.0 (2.0.0-dev.67.0), we faced following issue:
DDC adds
<script defer="" src="/packages/$sdk/dev_compiler/amd/require.js"></script>
to page, which defines global functionsrequire
anddefine
.That fact affects some third-party libraries, that are also imported to project.
If such library sees global
define
function, it defines new module, otherwise - set global variable.Problem is, we don't use requirejs in production environment.
Of course, we can add condition: load library via requirejs in dev-environment, by script adding - in prod one.
But I think, that can be a common problem for large products.
Another possible solution: move ddc's requirejs to some namespace...
The text was updated successfully, but these errors were encountered: