Global scripts are ignored
See original GitHub issueBug Report
What is the expected behavior?
The list of global scripts defined in angular.json
should be compiled into the server code.
What is the current behavior?
The list of global scripts defined in angular.json
are ignored.
What modules are related to this issue?
idk
Minimal reproduction with instructions:
To reproduce, clone the universal-starter
repo.
In src/app/app.component.ts
add this function declaration:
declare function globalFunction(): void;
And call it in the constructor:
export class AppComponent {
constructor() { globalFunction(); }
}
Next, create the file src/javascripts.js
and add this to it:
function globalFunction() {
console.log("Hello, world!");
}
Finally, edit angular.json
and add the new JavaScript file to the scripts
array:
"scripts": [
"src/javascripts.js"
]
Run ng serve
and visit http://localhost:4200
…you should see “Hello, world!” printed to the JavaScript console.
Now build the Universal app using npm run build:prerender
…you should see the error: ReferenceError: globalFunction is not defined
.
What is the use-case or motivation for changing an existing behavior?
It is common to include global scripts in the scripts
attribute of angular.json
. However, when running things out of Angular Universal, these scripts are ignored causing runtime errors.
Environment:
@nguniversal versions
- aspnetcore-engine:
- common:
- express-engine:
- hapi-engine:
- module-map-ngfactory-loader:
Angular CLI: 7.1.4
Node: 8.10.0
OS: linux x64
Angular: 7.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.11.4
@angular-devkit/build-angular 0.11.4
@angular-devkit/build-optimizer 0.11.4
@angular-devkit/build-webpack 0.11.4
@angular-devkit/core 7.1.4 (cli-only)
@angular-devkit/schematics 7.1.4
@ngtools/webpack 7.1.4
@schematics/angular 7.1.4
@schematics/update 0.11.4
rxjs 6.3.3
typescript 3.1.6
webpack 4.23.1
Is there anything else we should know?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5
You can use external libraries by importing (using ES6 imports) them instead of using scripts which will make them globally available in the browser.
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.