Struggling to configure my Angular 4 application to work with windows authentication. It works fine with anonymous authentication, but fails when switched to windows auth. The initial error encountered was:
(index):38 Error: Fetch error: 401 Unauthorized
Instantiating http://localhost:1264/app/main.js
Loading app
at http://localhost:1264/node_modules/systemjs/dist/system.src.js:1500:13 [<root>]
at Zone.run (http://localhost:1264/node_modules/zone.js/dist/zone.js:125:43) [<root> => <root>]
at http://localhost:1264/node_modules/zone.js/dist/zone.js:760:57 [<root>]
at Zone.runTask (http://localhost:1264/node_modules/zone.js/dist/zone.js:165:47) [<root> => <root>]
at drainMicroTaskQueue (http://localhost:1264/node_modules/zone.js/dist/zone.js:593:35) [<root>]
at <anonymous> [<root>]
The issue seems linked to the way `main.js` is loaded using SystemJs in `Systemjs.config.js` file:
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
To resolve this, additional attributes are suggested:
packages: {
app: {
main: './main.js',
defaultExtension: 'js',
format: 'register',
scriptLoad: true
},
Adding `format` and `scriptLoad` attributes helps overcome the authorization issues, but triggers another error:
Uncaught Error: Module name "@angular/platform-browser-dynamic" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded
at F (require.js:7) [<root>]
at Object.m [as require] (require.js:26) [<root>]
at requirejs (require.js:32) [<root>]
at :1264/app/main.js:2:34 [<root>]
This new error arises from a `require` statement within `main.js`, causing conflicts within the SystemJs context.
The usage of `require` stems from the module setting in the typescript json file. Setting it to commonjs avoids 401 unauthorized errors, unlike other module types such as system.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
...
}
If interested, the application developed in Visual Studio 2017 Enterprise is available on Bitbucket under the repository named Angular2VS2015.
In summary, how can I make my app function properly under windows authentication?