Module not found: Error: Cannot resolve module 'fs'
Module not found: Error: Cannot resolve module 'fs' in
我正在尝试集成ADAL JS示例代码:
https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/master/sample/client-credentials-sample.js到sharepoint框架客户端webpart:
我的代码很简单,我已经安装了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',
参见这里和这里
相关文章:
- 节点fs.stat名称未定义
- 为什么要对define.md和module.exports进行条件检查,以及条件何时通过
- Module.start()已激发两次
- module.js在运行iron节点时找不到模块
- nodeJS:使用(fs)尝试访问静态资源,但收到404错误
- 当路径有空格时,NodeJS fs.writeFile在linux上失败
- fs.statSync包含在函数中时抛出错误
- 读取不带fs的txt文件nodejs(来自url)
- 如果文件不存在,fs.watch是否有错误处理程序
- ES6to5, ES6 Module Transpiler and Babel
- 为什么fs.readFile在windows上花费太多时间
- 使用fs.readdir在vps上返回ENOENT,但在localhost上不返回
- 在jasmine规范中使用module.exports
- NodeJS FS 不从多个文件返回数据
- 我们可以在一个js文件中有多个module.exports语句吗
- fs.readFileSync()在express js应用程序中失败
- 为什么这个 fs.readFile 循环没有将其结果推送到我的数组
- 使用 fs/nodejs 的图像未显示在画布上
- 使用 Node.js 和 socket.io 和 fs 动态显示图像
- Module not found: Error: Cannot resolve module 'fs'