2

我需要针对 Microsoft Windows Azure AD 实施 adal 进行身份验证。我正在使用 angular2 CLI 和angular2-adal

问题是当我将 AdalService 添加到提供程序时会出现此错误:

Uncaught Error: Cannot find module "adal"
at webpackMissingModule (adal.service.js:20)
at Object.<anonymous> (adal.service.js:20)
at __webpack_require__ (bootstrap dd353fe…:52)
at Object.<anonymous> (services.js:8)
at __webpack_require__ (bootstrap dd353fe…:52)
at Object.<anonymous> (core.js:12)
at __webpack_require__ (bootstrap dd353fe…:52)
at Object.638 (create-users.component.ts:15)
at __webpack_require__ (bootstrap dd353fe…:52)
at Object.647 (header.component.ts:47)

而这个:

    client?93b6:80./~/angular2-adal/services/adal.service.js
Module not found: Error: Can't resolve 'adal' in 'D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\angular2-adal\services'
resolve 'adal' in 'D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\angular2-adal\services'
  Parsed request is a module
  using description file: D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\angular2-adal\package.json (relative path: ./services)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\angular2-adal\package.json (relative path: ./services)
    resolve as module
      looking for modules in D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\src
        using description file: D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\package.json (relative path: ./src)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\package.json (relative path: ./src)
          using description file: D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\package.json (relative path: ./src/adal)
            as directory
              D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\src\adal doesn't exist
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\src\adal doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\src\adal.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\src\adal.js doesn't exist
      looking for modules in D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules
        using description file: D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\package.json (relative path: ./node_modules)
          using description file: D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\package.json (relative path: ./node_modules/adal)
            as directory
              D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\adal doesn't exist
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\adal doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\adal.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\adal.js doesn't exist
[D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\src\adal]
[D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\src\adal]
[D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\src\adal.ts]
[D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\src\adal.js]
[D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\adal]
[D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\adal]
[D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\adal.ts]
[D:\Git\SistecreditoTutoriales\SistecreditoTutoriales\src\TutorialesWeb\node_modules\adal.js]

 @ ./~/angular2-adal/services/adal.service.js 20:14-29
 @ ./~/angular2-adal/services.js
 @ ./~/angular2-adal/core.js
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

我一直在寻找可能的解决方案,但少数答案没有好的结果。

4

2 回答 2

3

原来,图书馆 angular2-adal 有一个错误,可以解决这个图书馆 ng2-adal中的其他人。然后您需要解决 2 个问题命名空间并且无法解析“adal”。我以这种方式解决了它:

  1. 命名空间:您需要添加///<reference path="../node_modules/ng2-adal/ts/adal/index.d.ts" />typings.d.ts

  2. Can´t resolve 'adal' : 你需要在这个路由 node_modules/angular-cli/models/webpack-build-commond.js 中修改一个 webpack 文件,寻找这样的东西:

        resolve:{
           extensions: ['.ts', '.js'],
           modules: [nodeModules],
        },
    

你需要添加这个:

alias: { 'adal': 'adal-angular' }

请记住,我使用 angular2 CLI。

如果有人知道向 webpack 添加别名的更好方法,请告诉我

于 2016-12-29T13:29:30.080 回答
2

尝试安装 adal-ts:

npm install adal-ts --save

它基本上是在 typescript 中重写 adal.js。

于 2016-12-28T09:45:47.810 回答