Closed
Description
Bug Report or Feature Request (mark with an x
)
- [X ] bug report -> please search issues before submitting
- [ ] feature request
Command (mark with an x
)
- [ ] new
- [ ] build
- [ ] serve
- [X] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
Versions
@angular-devkit/build-angular >= 0.7.0
passes with 0.6.8, fails with anything after 0.7.0
ng --version
Angular CLI: 6.1.4
Node: 10.9.0
OS: win32 x64
Angular: 6.1.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.7.4
@angular-devkit/build-angular 0.7.4
@angular-devkit/build-optimizer 0.7.4
@angular-devkit/build-webpack 0.7.4
@angular-devkit/core 0.7.4
@angular-devkit/schematics 0.7.4
@angular/cli 6.1.4
@ngtools/webpack 6.1.4
@schematics/angular 0.7.4
@schematics/update 0.7.4
rxjs 6.2.2
typescript 2.7.2
webpack 4.9.2
Repro steps
ng new on-error
cd on-error
cat > src/app/test-onerror.spec.ts << 'EOF'
import { timer } from 'rxjs';
describe('window.onerror', () => {
it('returns "Script Error." instead of actual error', async () => {
setTimeout(() => { throw new Error('Go boom'); });
const onErrorSpy = spyOn(window, 'onerror');
await timer().toPromise();
expect(onErrorSpy).toHaveBeenCalledTimes(1);
const ev: ErrorEvent = onErrorSpy.calls.argsFor(0)[0];
console.log(`ErrorEvent
filename: '${ev.filename}':'${ev.lineno}'
message: '${ev.message}'
error: '${ev.error && ev.error.message}'`
);
expect(ev.error).not.toBe(null);
});
});
EOF
ng test --watch false
The log given by the failure
$ ng test --watch false
21 08 2018 16:42:51.305:WARN [karma]: Port 9876 in use
21 08 2018 16:42:51.309:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9877/
21 08 2018 16:42:51.309:INFO [launcher]: Launching browser Chrome with unlimited concurrency
21 08 2018 16:42:51.340:INFO [launcher]: Starting browser Chrome
21 08 2018 16:42:54.772:INFO [Chrome 68.0.3440 (Windows 10.0.0)]: Connected on socket Z7nV7JlOQnNqP43BAAAA with id 83287909
LOG: 'ErrorEvent
filename: '':'0'
message: 'Script error.'
error: 'null''
Chrome 68.0.3440 (Windows 10.0.0): Executed 1 of 4 SUCCESS (0 secs / 0.044 secs)
LOG: 'ErrorEvent
filename: '':'0'
message: 'Script error.'
Chrome 68.0.3440 (Windows 10.0.0) window.onerror returns "Script Error." instead of actual error FAILED
Expected null not to be null.
at eval (webpack:///./src/app/test-onerror.spec.ts?:54:42)
at step (webpack:///./src/app/test-onerror.spec.ts?:33:23)
at Object.eval [as next] (webpack:///./src/app/test-onerror.spec.ts?:14:53)
at fulfilled (webpack:///./src/app/test-onerror.spec.ts?:5:58)
Chrome 68.0.3440 (Windows 10.0.0): Executed 2 of 4 (1 FAILED) (0 secs / 0.05 secs)
Chrome 68.0.3440 (Windows 10.0.0) window.onerror returns "Script Error." instead of actual error FAILED
Expected null not to be null.
at eval (webpack:///./src/app/test-onerror.spec.ts?:54:42)
at step (webpack:///./src/app/test-onerror.spec.ts?:33:23)
at Object.eval [as next] (webpack:///./src/app/test-onerror.spec.ts?:14:53)
Chrome 68.0.3440 (Windows 10.0.0): Executed 4 of 4 (1 FAILED) (0.212 secs / 0.197 secs)
Desired functionality
The ErrorEvent passed to window.onerror should contain the error:
LOG: 'ErrorEvent
filename: 'http://localhost:9877/_karma_webpack_/vendor.js':'71851'
message: 'Uncaught Error: Go boom'
Chrome 68.0.3440 (Windows 10.0.0): Executed 4 of 4 SUCCESS (0.122 secs / 0.171 secs)
Mention any other details that might be useful
Looking at this stack overflow, I assume this is a cross origin issue. I noticed the context.html has the crossorigin attribute set on all the script tags, so not sure what's actually going wrong.
https://stackoverflow.com/questions/5913978/cryptic-script-error-reported-in-javascript-in-chrome-and-firefox