Repository navigation
Remove System.import() usage in favor of import() #21560
Copy link
Copy link
Closed
Labels
P5The team acknowledges the request but does not plan to address it, it remains open for discussionThe team acknowledges the request but does not plan to address it, it remains open for discussionarea: coreIssues related to the framework runtimeIssues related to the framework runtimefeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
Milestone
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Currently Angular core makes use of a System.import() call to load templates (html/css) and lazy modules:
| return System.import(module) | |
| .then((module: any) => module[exportName]) | |
| .then((type: any) => checkNotEmpty(type, module, exportName)) | |
| .then((type: any) => this._compiler.compileModuleAsync(type)); |
In the past System.import was expected to become a standard, but import() was settled upon instead.
Modern tooling is beginning to deprecate (notably Webpack 4 webpack/webpack#6321) System.import() detection in favor of the standard and it should not be unexpected that more follow suit.
Expected behavior
The standard import() is used, so that tooling that supports code splitting can detect it.
Minimal reproduction of the problem with instructions
The SystemJS loader can be found at https://github.com/angular/angular/blob/master/packages/core/src/linker/system_js_ng_module_factory_loader.ts.
What is the motivation / use case for changing the behavior?
Remain compatible with modern tooling.
Environment
Angular version: 2, 4 and 5
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P5The team acknowledges the request but does not plan to address it, it remains open for discussionThe team acknowledges the request but does not plan to address it, it remains open for discussionarea: coreIssues related to the framework runtimeIssues related to the framework runtimefeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
Activity
robwormald commentedon Jan 16, 2018
In theory I'm all for this, but what happens with ES5 code? What does
import()transpile down to do for a UMD or CommonJS bundle? It doesn't seem like this is something we can do in a backwards compatible fashion, unless I'm missing something.I'd prefer to drop this whole abstraction in favor of just doing it inline:
but that's going to be gated on inlining factories (so we don't need to do the rewrite), or making CLI smart enough to pick up imports like ^ and rewrite them.
filipesilva commentedon Jan 16, 2018
Personally I'd prefer dropping the abstraction as well, but haven't considered the implications of that option much.
The CLI could be smart enough to pick up those imports I think. We already have to do that for
System.import.Toxicable commentedon Jan 16, 2018
It was my understanding that
import()was only available with when targetinges2015as a requirement of TS, meaning it does not support es5.filipesilva commentedon Jan 16, 2018
It's not a big problem for applications proper. It's more of an issue for libraries and packaging concerns. If Angular were to have
import()in it's codebase, it could only be consumed by tooling that understoodimport()and know to also load what the statement was referencing.On formats like UMD or CommonJS it would have to be provided externally. I don't think it transpiles down to anything.
trotyl commentedon Jan 17, 2018
@Toxicable Dynamic import has no restriction on
target, but onmodule. All module types exceptes2015are allowed, for example with source:To
module: esnext:To
module: commonjs:To
module: amd:To
module: system:To
module: umd:Toxicable commentedon Jan 17, 2018
@trotyl Right, my mistake I confused the two of them.
However, this would still be a breaking change since most people use
module: "es2015"since that's the CLI's defaulttrotyl commentedon Jan 17, 2018
@Toxicable Just did a check, the
modulerestriction is only meant for.tssource files (compilation), not for.d.tsdeclaration files (type-checking).The emited
.d.tsis:There's no pattern indicating the dynamic import.
Toxicable commentedon Jan 17, 2018
Oh that's an interesting point maybe it would be fine to make that change then
filipesilva commentedon Jan 17, 2018
Great breakdown @trotyl!
IgorMinar commentedon Jan 20, 2018
@filipesilva will this be still compatible with webpack 3?
filipesilva commentedon Jan 29, 2018
@IgorMinar Webpack 3 supports
import()as the primary code splitting construct https://webpack.js.org/guides/code-splitting/#dynamic-imports.System.import()isn't listed in the docs even, but it is supported since the Webpack 3 betas.dennis-johnson-dev commentedon Mar 2, 2018
FWIW, I tried
{ loadChildren: import('./some-cool-module').then(mod => mod.ModuleName) }and it seems to work in JIT mode, but I had to switch to{ loadChildren: './path-to-module#ModuleName' }to get it to work with AOT.Was using Angular 5.x.x and Webpack 3.x.x.
If
importwas used in Angular, would that mean that we could code split in more places than just the routes and still have AOT work? That would be amazing. Thinking the equivalent of something like the react-loadable project where component level splitting was an option without having to tie the split to the router.28 remaining items
wKoza commentedon Aug 5, 2019
In Angular 8 this warning wasn't resolved
almartino commentedon Dec 20, 2019
Please, see the comment by @ermarkar #23426 (comment)
thw0rted commentedon Dec 30, 2019
Good to know how to hide the warning, @almartino , but the team really should move away from SystemJS imports soon. It's practically 2020 and we have lots of support for native
import().iranicus commentedon Feb 23, 2020
In Angular 9 this warning wasn't resolved :'( but using what PKief suggested worked for me with webpack 4
seahindeniz commentedon Aug 9, 2020
Can anyone care to explain what is the downside of disabling the SystemJS other than freeing the global variable "System"?
Quoting from Performance section
rahulserver commentedon May 6, 2021
Facing this issue with
"@angular/core": "^11.2.10",petebacondarwin commentedon May 6, 2021
@rahulserver - which issue exactly are you facing? This is a feature request.
rahulserver commentedon May 6, 2021
@petebacondarwin I just imported that angular core library in an ionic project (Which is actually a vue project) because I had to us a barcode scanner module https://ionicframework.com/docs/native/barcode-scanner (which needs angular/core in a vue js project).
And I get this in console whenever i run the project:
petebacondarwin commentedon May 7, 2021
So the issue is that you are receiving a warning due to this deprecated
System.importcall in the code.This will be removed in the next major release (v13 since 12.0.0 is about to ship next week).
JoostK commentedon Sep 30, 2021
SystemJsNgModuleFactoryLoaderhas been removed in #43591.angular-automatic-lock-bot commentedon Oct 31, 2021
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.