Importing debug in angular 2 app with system.js
See original GitHub issueI am working on a MEAN stack app with Angular 2 frontend. I have successfully used debug
in the express app. However I am unable to cleanly import debug in app.components.ts
or main.module.ts
. Any idea on how to proceed?
<script src="/node_modules/debug/debug.js"></script>
Results in error:Uncaught ReferenceError: module is not defined
<script>System.import('./node_modules/debug/debug.js');</script>
Not good either:zone.js:101 GET http://localhost:8002/ms.js 404 (Not Found)
Some dependency script not able to load.import { debug } from '../../../node_modules/debug/debug.js';
inside any app file also gives error:zone.js:101 GET http://localhost:8002/ms.js 404 (Not Found); (index):25 Error: Error: XHR error (404 Not Found) loading http://localhost:8002/ms.js(…)
Issue Analytics
- State:
- Created 7 years ago
- Comments:17 (5 by maintainers)
Top Results From Across the Web
Importing debug in angular 2 app with system.js · Issue #305
I am working on a MEAN stack app with Angular 2 frontend. I have successfully used debug in the express app. However I...
Read more >Find Out How to Debug Angular 2 Applications
Then, import the Logger in the file where your Angular 2's bootstrap() function resides and put it as an argument in the function....
Read more >Importing visionmedia debug in Angular 2 app with System ...
I am working on a MEAN stack app with Angular 2 frontend. I have successfully used debug in the express app. However I...
Read more >Everything you need to know about debugging Angular ...
This is easy to do if you're using module loader like SystemJS. It loads modules using System.import method which returns a promise that...
Read more >Chapter 2. Getting started with Angular - liveBook · Manning
In this chapter, we'll start discussing how you develop Angular applications using modern tools and web technologies like annotations, ES6 modules, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Using the Angular CLI 1.0.0 (which uses Webpack) I got debug working using the following steps:
First of, nstalling and configuring the debug library for angular (see also CLI wiki entry)
npm install debug --save
npm install @types/debug --save-dev
"debug"
to the"types": [ ]
insrc/tsconfig.app.json
Then in any
ts
file use (import and define namespace) it as following:Finally to enable the debug in the console, type the following in the console (see also NPM debug package page)
localStorage.debug = 'app:*'
debug
as key andapp:*
as value.Differences with the initial suggestion:
node_modules/debug/debug.js
debugApp
to the global windowI’m not 100% sure if this is the correct way, but it works.
I took some inspiration from Importing lodash into angular2 + typescript application and finally figured out how to import it. No console errors and no compiler errors this time.
First I should mention: when upgrading from
typescript 1
totypescript 2
thetypings
tool gets deprecated. Instead,npm
package manager is used to install type definitions.I followed these steps:
npm install debug --save
npm install @types/debug --save
system.config.js
system.config.js:
import * as debug from 'debug';
<script>System.import('debug');</script>
Untill now this should work, however a pesky error persists:
GET http://localhost:8002/ms.js 404 (Not Found)
. I fixed this by editingnode_modules/debug/debug.js
.exports.humanize = require('ms');
withexports.humanize = require('node_modules/ms/index');
.I am not sure what this implies for other use cases of
debug
. If you have any suggestions on how to improve this solution so it is not necessary to edit insidenode_modules/debug/debug.js
write a comment.Usage in browser
Preferably in app.component.ts or main.module.ts write:
In any other .ts file:
Finally in the console type as you need:
SOLVED P.S. Please provide an example in documentation that covers this issue. It is not obvious at all for newcomers how to solve this issue.