使用 System.js 在 Angular 2 应用程序中导入 Visionmedia 调试以及如何记录消息?

2024-01-25

我正在使用 Angular 2 前端开发 MEAN 堆栈应用程序。我已经成功使用了debug在快递应用程序中。但是我无法干净地导入调试app.components.ts or main.module.ts。关于如何继续的任何想法?

  • <script src="/node_modules/debug/debug.js"></script>结果出错:Uncaught ReferenceError: module is not defined
  • <script>System.import('./node_modules/debug/debug.js');</script>也不好:zone.js:101 GET http://localhost:8002/ms.js 404 (Not Found)某些依赖脚本无法加载。
  • import { debug } from '../../../node_modules/debug/debug.js';在任何应用程序文件中也会给出错误: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(…)

Solved

感谢@candidJ,终于解决了。我强烈建议使用此工具来调试您的应用程序。完成开发后,重构所有console.log()语句进入debugApp()而不是删除它们。请记住,您可以为每个模块命名它们,并单独或集体启用/禁用它们。这些对于稍后通过代码回溯进行维护或调试的其他开发人员来说将非常有用。


你需要安装打字功能debug库以便在中使用它ts文件。 types 管理您的打字稿定义。

Typings 是管理和安装 TypeScript 的简单方法 定义。

在这里你可以如何做到这一点:

# Install Typings CLI utility.
  npm install typings --global    

# Find a definition by name.
typings search --name debug

# If you use the package as a module:
# Install non-global typings (defaults to "npm" source, configurable through `defaultSource` in `.typingsrc`).

typings install debug --save

然后你可以尝试将其导入到你的index.html(全球)使用either方式(正如你所做的那样):

  • <script src="/node_modules/debug/debug.js"></script>

  • <script>System.import('./node_modules/debug/debug.js');</script>

有关打字的更多信息请参阅:https://github.com/typings/typings https://github.com/typings/typings

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 System.js 在 Angular 2 应用程序中导入 Visionmedia 调试以及如何记录消息? 的相关文章

随机推荐