question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Script imports are modules by default

See original GitHub issue

🐞 Bug report

Command (mark with an x)

  • build
  • serve

Is this a regression?

Yes, the previous version in which this bug was not present was: 12.2.13

Description

Now that dynamic imports are of type="module" by default this breaks imports of legacy libraries that were not built with strict mode in mind. We are using calentim datepicker in a lazy loaded module(also loading the library with dynamic import) in the project and with the transition to angular 13 and specifically with the change of default webpack output to produce script tags with the type module in https://github.com/angular/angular-cli/commit/f53bf9dc21ee9aa8a682b8a82ee8a9870fa859e1 the library breaks as it is not written in strict mode. I understand the desire to move to modules by default, but would like to have an option to import legacy code as 'text/javascript'. This feels like a breaking change that didn’t get a mention in https://update.angular.io notes either.

πŸ”¬ Minimal Reproduction

await import('./legacy/library.js') Using the library will brake during runtime if it violates strict mode.

🌍 Your Environment

ng version



Angular CLI: 13.0.2
Node: 16.13.0
Package Manager: npm 8.1.0
OS: win32 x64

Angular: 13.0.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1300.2
@angular-devkit/build-angular   13.0.2
@angular-devkit/core            13.0.2
@angular-devkit/schematics      13.0.2
@angular/cli                    13.0.2
@schematics/angular             13.0.2
rxjs                            6.6.7
typescript                      4.4.4

Anything else relevant? I understand the ability to provide custom builder in angular.json, but would like to avoid it as it is a large undertaking to keep it updated between angular releases than being able to configure this some other way.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
andreialecucommented, Nov 17, 2021

Yes, that is totally understandable.

I just thought dropping support for modules would be something that would be important to mention in the change log.

Would have appreciated a warning. πŸ™‚

Otherwise, I agree with browser support approach.

2reactions
andreialecucommented, Nov 17, 2021

This is the only issue I found related to this subject, apologies to hijack it.

We recently hit a critical breaking change with Angular 13 and older SmartTV browsers. We have some customers using Samsung TVs from 2018. Those TVs use Chromium 57 and have not had an update to the browser version, even though they had firmware updates as recent as 2021.

Chrome 57 is from before the time of script type="module", and we already updated our app - not seeing anything concerning in the list of breaking changes (except dropping support for IE 11, but that didn’t seem relevant).

Is there any way to force Angular 13 to create normal/non-module scripts and script tags?

Or at least, could you point me to where this change was made? I’d be interested in trying to revert it in a fork so we can get unblocked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

import - JavaScript - MDN Web Docs - Mozilla
If an import declaration is encountered in non-module contexts (for example, <script> tags without type="module" , eval , new Function , whichΒ ...
Read more >
6. Modules β€” Python 3.11.1 documentation
Modules can import other modules. It is customary but not required to place all import statements at the beginning of a module (or...
Read more >
Documentation - Modules - TypeScript
In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or export is considered a module. Conversely, a file without...
Read more >
Modules, introduction - The Modern JavaScript Tutorial
A module is just a file. One script is one module. As simple as that. Modules can load each other and use special...
Read more >
Import-Module (Microsoft.PowerShell.Core)
By default, Import-Module imports all members that the module exports, but you can use the Alias, Function, Cmdlet, and Variable parameters to restrict...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found