msal npm build运行因加载程序问题而失败

时间:2018-07-23 21:41:17

标签: testing npm build msal

我正在尝试构建msal,以便可以与nodejs一起使用。具体来说,我想验证端到端webdriverio测试中测试用户是否收到了电子邮件。

我遵循了npm msal指南here,走得很远,但是在以下过程中遇到了一些错误:

npm run build

npm run build

> msal@0.1.7 build C:\Users\User\TestAutomation\node_modules\msal
> npm run clean && npm run doc && npm run build:modules && webpack && grunt && npm test


> msal@0.1.7 clean C:\Users\User\TestAutomation\node_modules\msal
> shx rm -rf dist docs lib-commonjs lib-es6


> msal@0.1.7 doc C:\Users\User\TestAutomation\node_modules\msal
> typedoc --out ./docs ./src/**/* --gitRevision dev


Using TypeScript 2.2.2 from C:\Users\User\TestAutomation\node_modules\msal\node_modules\typedoc\node_modules\typescript\lib
Rendering [========================================] 100%

Documentation generated at C:\Users\User\TestAutomation\node_modules\msal\docs


> msal@0.1.7 build:modules C:\Users\User\TestAutomation\node_modules\msal
> tsc && tsc -m es6 --outDir lib-es6

Hash: 898d9837b77694c4a729
Version: webpack 3.12.0
Time: 244ms
          Asset     Size  Chunks             Chunk Names
        msal.js  8.59 kB    0, 1  [emitted]  msal
    msal.min.js  3.26 kB    1, 0  [emitted]  msal.min
    msal.js.map  3.67 kB    0, 1  [emitted]  msal
msal.min.js.map  14.4 kB    1, 0  [emitted]  msal.min
   [0] ./src/UserAgentApplication.ts 271 bytes {0} {1} [built] [failed] [1 error]
   [1] ./src/Logger.ts 290 bytes {0} {1} [built] [failed] [1 error]
   [2] multi ./src/index.ts 28 bytes {0} {1} [built]
   [3] ./src/index.ts 354 bytes {0} {1} [built]
   [4] ./src/User.ts 248 bytes {0} {1} [built] [failed] [1 error]
   [5] ./src/Constants.ts 357 bytes {0} {1} [built] [failed] [1 error]
   [6] ./src/RequestInfo.ts 247 bytes {0} {1} [built] [failed] [1 error]
   [7] ./src/Authority.ts 209 bytes {0} {1} [built] [failed] [1 error]

ERROR in ./src/Logger.ts
Module parse failed: Unexpected token (26:7)
You may need an appropriate loader to handle this file type.
| import { Utils } from "./Utils";
|
| export interface ILoggerCallback {
|   (level: LogLevel, message: string, containsPii: boolean): void;
| }
 @ ./src/index.ts 2:0-34 3:0-36
 @ multi ./src/index.ts

ERROR in ./src/Constants.ts
Module parse failed: Unexpected token (28:31)
You may need an appropriate loader to handle this file type.
|  */
| export class Constants {
|   static get errorDescription(): string { return "error_description"; }
|   static get error(): string { return "error"; }
|   static get scope(): string { return "scope"; }
 @ ./src/index.ts 5:0-40
 @ multi ./src/index.ts

ERROR in ./src/RequestInfo.ts
Module parse failed: Unexpected token (28:7)
You may need an appropriate loader to handle this file type.
|  */
| export class TokenResponse {
|   valid: boolean;
|   parameters: Object;
|   stateMatch: boolean;
 @ ./src/index.ts 6:0-45
 @ multi ./src/index.ts

ERROR in ./src/User.ts
Module parse failed: Unexpected token (30:17)
You may need an appropriate loader to handle this file type.
| export class User {
|
|     displayableId: string;
|     name: string;
|     identityProvider: string;
 @ ./src/index.ts 4:0-30
 @ multi ./src/index.ts

ERROR in ./src/Authority.ts
Module parse failed: Unexpected token (34:7)
You may need an appropriate loader to handle this file type.
|  * @hidden
|  */
| export enum AuthorityType {
|   Aad,
|   Adfs,
 @ ./src/index.ts 7:0-38
 @ multi ./src/index.ts

ERROR in ./src/UserAgentApplication.ts
Module parse failed: Unexpected token (39:8)
You may need an appropriate loader to handle this file type.
| import { AuthorityFactory } from "./AuthorityFactory";
|
| declare global {
|     interface Window {
|         msal: Object;
 @ ./src/index.ts 1:0-62 8:0-51
 @ multi ./src/index.ts
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! msal@0.1.7 build: `npm run clean && npm run doc && npm run build:modules && webpack && grunt && npm test`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the msal@0.1.7 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

我认为这是通天塔错误:

You may need an appropriate loader to handle this file type

但是我不确定如何解决。我也尝试安装babel,不确定是否需要在某处安装它。

我对这些工具有些陌生,所以我确定这是一个简单的错误。我花了一些时间在上面,所以我想伸出援手。如果我解决了,我会更新这个问题。

感谢MS团队提供了msal。

更新:包括webpack.config.js

npm install msal 自动生成的webpack.config.js:

var path = require("path");
var webpack = require("webpack");

var PATHS = {
    entryPoint: path.resolve(__dirname, 'src/index.ts'),
    bundles: path.resolve(__dirname, 'dist'),
}

var config = {

    entry: {
        'msal': [PATHS.entryPoint],
        'msal.min': [PATHS.entryPoint]
    },

    output: {
        path: PATHS.bundles,
        filename: '[name].js',
        libraryTarget: 'umd',
        library: 'Msal',
        umdNamedDefine: true
    },

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

    devtool: 'source-map',
    plugins: [

      new webpack.optimize.UglifyJsPlugin({
          minimize: true,
          sourceMap: true,
          include: /\.min\.js$/,
      })
    ],
    module: {

        loaders: [{
            test: /\.tsx?$/,
            loader: 'awesome-typescript-loader',
            exclude: /node_modules/,
            query: {
                declaration: false,
            }
        }]
    }
}

module.exports = config; 

1 个答案:

答案 0 :(得分:1)

You may need an appropriate loader to handle this file type表示您缺少特定文件类型的加载程序。

查看错误消息,似乎在.ts文件上失败。您是否有机会忘记为似乎失败的打字稿文件添加打字稿文件加载器(ts-loader)?

编辑

1)您正在使用loaders:作为装载机。我不知道这是否会在某种意义上影响它,因为似乎该配置仍然可以在Webpack 3中使用。 (我无法在Webpack 4配置中使用loaders:,因为编译时webpack将其标记为无效)。

因此,我想弄清楚它是否有很大的不同,并且在徘徊的同时,我确实找到了MSAL here的打字稿样本。看起来他们在配置中也正在使用规则。

 module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: 'awesome-typescript-loader'
      }
    ]
  },

老实说,我不知道这有什么不同。