gpt4 book ai didi

javascript - 找不到模块 : Error: Cannot resolve module 'fs' in

转载 作者:搜寻专家 更新时间:2023-10-30 20:43:42 25 4
gpt4 key购买 nike

我正在尝试集成 ADAL JS 示例代码:

https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/master/sample/client-credentials-sample.js

进入 Sharepoint 框架客户端 Web 部件:

我的代码很简单,我已经安装了npm、adal、fs、node-fs等

However I see this error

./~/adal-node/lib/util.js
Module not found: Error: Cannot resolve module 'fs' in /Users/luis.valencia/Documents/GraphSamples/Sample1/node_modules/adal-node/lib
resolve module fs in /Users/luis.valencia/Documents/GraphSamples/Sample1/node_modules/adal-node/lib
looking for modules in /Users/luis.valencia/Documents/GraphSamples/Sample1/node_modules/adal-node/lib
/Users/luis.valencia/Documents/GraphSamples/Sample1/node_modules/adal-node/lib/fs doesn't exist (module as directory)
resolve 'file' fs in /Users/luis.valencia/Documents/GraphSamples/Sample1/node_modules/adal-node/lib
resolve file

我的代码是这样的:

我什至评论了 require JS 行,但看起来 adal js 库本身使用了 FS,但似乎没有正确安装?

import {
BaseClientSideWebPart,
IPropertyPaneSettings,
IWebPartContext,
PropertyPaneTextField
} from '@microsoft/sp-client-preview';

import styles from './Hellomsgraph.module.scss';
import * as strings from 'hellomsgraphStrings';
import { IHellomsgraphWebPartProps } from './IHellomsgraphWebPartProps';
import * as MicrosoftGraph from "microsoft-graph"

const accessToken:string = "";
//var fs = require('fs');
var adal = require('adal-node');
var AuthenticationContext = adal.AuthenticationContext;


export default class HellomsgraphWebPart extends BaseClientSideWebPart<IHellomsgraphWebPartProps> {

public constructor(context: IWebPartContext) {
super(context);
}

public render(): void {
this.domElement.innerHTML = `
<div class="${styles.hellomsgraph}">
<div class="${styles.container}">
<div class="ms-Grid-row ms-bgColor-themeDark ms-fontColor-white ${styles.row}">
<div class="ms-Grid-col ms-u-lg10 ms-u-xl8 ms-u-xlPush2 ms-u-lgPush1">
<span class="ms-font-xl ms-fontColor-white">Welcome to SharePoint!</span>
<p class="ms-font-l ms-fontColor-white">Customize SharePoint experiences using Web Parts.</p>
<p class="ms-font-l ms-fontColor-white">${this.properties.description}</p>
<a href="https://github.com/SharePoint/sp-dev-docs/wiki" class="ms-Button ${styles.button}">
<span class="ms-Button-label">Learn more</span>
</a>
</div>
</div>
</div>
</div>`;
}

protected get propertyPaneSettings(): IPropertyPaneSettings {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

最佳答案

将此添加到 webpack.config.js

target: 'node',

参见 herehere

关于javascript - 找不到模块 : Error: Cannot resolve module 'fs' in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40541044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com