在Node.JS文档中,我发现了一句话
当文件直接从Node.js运行时,
require.main将设置为其模块.这意味着可以通过测试确定文件是否已直接运行require.main === module.
我想问一下main这里有什么,我main在源代码中找不到这个的定义,任何人都可以帮忙,谢谢!
我有一个正在构建到名为 的目录的包lib。结构如下:
- lib/
-- moduleA/
---- index.js
-- moduleB/
---- index.js
- src/
-- moduleA/
-- moduleB/
Run Code Online (Sandbox Code Playgroud)
并在package.json我指定:
"main": "./lib"
Run Code Online (Sandbox Code Playgroud)
在另一个项目中,我尝试从上面的包中导入特定模块,如下所示:
import moduleA from '@scope/packageA/moduleA';
Run Code Online (Sandbox Code Playgroud)
但 Webpack 无法解析该模块,并表示:
找不到模块:错误:无法解析“@scope/packageA/moduleA”
但是,如果我直接从以下位置导入,它确实有效lib:
import moduleA from '@scope/packageA/lib/moduleA;
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?我的理解是 Webpack 尊重main包的入口,并且应该可以从入口点开始从层次结构中的任何位置导入。
我创建了一个带有OWIN中间件的WebAPI OData 3.0 Web服务,该中间件配置为使用Windows Azure Active Directory进行身份验证.ODataControllers标有一个[Authorize]属性,IAppBuilder配置如下:
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters {
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
},
});
Run Code Online (Sandbox Code Playgroud)
ida:Tenant是我的Windows Azure租赁,ida:Audience是App ID Uri.
现在,我想使用Excel PowerQuery使用此服务,使用AzureAD中的帐户进行身份验证.但是,当我选择"组织帐户"并尝试"登录"时,我收到以下错误:
无法连接.此资源不支持此凭据类型.
在Fiddler中,我可以看到请求是使用Bearer标头进行的,但它是空的.
我想实现类似于查询AzureAD Graph时的行为.
例如,如果我尝试使用https://graph.windows.net/.onmicrosoft.com/users?api-version=2013-04-05,则会打开一个单点登录窗口,在Fiddler中我可以看到令牌被传递.
我怎样才能实现这种行为?我错过了什么?
谢谢!
single-sign-on odata asp.net-web-api azure-active-directory powerquery
我的组件有:
class Search extends Component {
constructor(props) {
super(props);
this.state = {
searchTerm:
typeof this.props.match.params.searchTerm !== "undefined"
? this.props.match.params.searchTerm
: ""
};
}
Run Code Online (Sandbox Code Playgroud)
测试是:
test("Search should render correct amount of shows", () => {
const component = shallow(<Search shows={preload.shows} />);
expect(component.find(ShowCard).length).toEqual(preload.shows.length);
});
Run Code Online (Sandbox Code Playgroud)
我明白了
TypeError:无法读取undefined的属性'params'
我如何解决这个问题或如何在我的测试中设置查询参数?
我正在尝试恢复文件下载.
我使用下面的代码成功下载了我需要的文件.
downlaodfile = new WebClient();
// downlaodfile.Headers.Add("Range", "bytes=0-600000");
downlaodfile.DownloadFileAsync(new Uri(video.DownloadUrl), @"C:\Videofile.pm4");
Run Code Online (Sandbox Code Playgroud)
当我取消注释下面的0字节时,问题开始了
downlaodfile.Headers.Add("Range", "bytes=0-600000");
Run Code Online (Sandbox Code Playgroud)
使用WebClient类恢复的正确方法是什么?
我加入的帮助下部件动态require.ensure()ES6及getComponent()的react-router。一旦我为每个具有相同键(例如“A”)的记录打开单独的选项卡,我就会收到上述错误。我的动态加载是这样的:
require.ensure([], (require) => {
const req = require('./components/A).default
const reducer= require('./modules').default
injectReducer(store, {
key: 'A',
reducer
})
cb(null, req)
})
Run Code Online (Sandbox Code Playgroud)
我的代码createstore()是这样的:
export const makeRootReducer = (asyncReducers) => {
return combineReducers({
B,
C,
...asyncReducers
})
}
export const injectReducer = (store, { key, reducer }) => {
if (Object.hasOwnProperty.call(store.asyncReducers, key))return
store.asyncReducers[key] = reducer
store.replaceReducer(makeRootReducer(store.asyncReducers))
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是,在浏览器选项卡打开时,除了第一次将警告显示为:
在减速器接收到的先前状态中发现意外的键“A” 期望找到已知的减速器键之一:“B”、“C”。意外的键将被忽略。
如果我最初会通过 Key 'A'combineReducers()那么这个警告就会消失。但这combineReducers()是全局的,它会保持减速器的状态,所以我不想在初始加载时传递这个 Key。我该如何解决此警告,请帮助我。
reactjs ×2
babeljs ×1
c# ×1
ecmascript-6 ×1
enzyme ×1
http ×1
javascript ×1
jest ×1
node.js ×1
npm ×1
odata ×1
powerquery ×1
react-redux ×1
redux ×1
webclient ×1
webpack ×1