testing - msal npm 构建运行因加载程序问题而失败
问题描述
我正在尝试构建 msal,以便可以将它与 nodejs 一起使用。具体来说,我想在端到端 webdriverio 测试中验证测试用户是否收到了电子邮件。
我在这里遵循了 npm msal 指南,并取得了相当大的进展,但在以下过程中遇到了一些错误:
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:
我认为这是一个 babel 错误:
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;
解决方案
You may need an appropriate loader to handle this file type
指的是您缺少特定文件类型的加载器这一事实。
查看错误消息,.ts 文件似乎失败了。您是否有可能忘记为似乎失败的打字稿文件添加打字稿文件加载器( ts-loader )?
编辑
1)您正在使用loaders:
装载机。我不知道这是否会在任何意义上影响它,因为似乎该配置仍然可以在 Webpack 3 中使用。(我不能loaders:
在我的 Webpack 4 配置中使用,因为它在编译时被 webpack 标记为无效)。
因此,我想弄清楚它是否有很大的不同,并且在四处走动时,我确实在这里找到了 MSAL 的打字稿样本。看起来他们在配置中也使用了规则。
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
}
]
},
老实说,我不知道这是否会有所作为。