AMD externals fail silently if libraryTarget is not 'amd'
#8,079 opened on 2018/09/24
Repository metrics
- Stars
- (65,766 個のスター)
- PR merge metrics
- (平均マージ 1d 5h) (30d で 180 merged PRs)
説明
Bug report
What is the current behavior?
External dependencies that are only available via AMD are only supported if the output libraryTarget is also 'amd'. This is rather surprising, and not at all documented.
If the current behavior is a bug, please provide the steps to reproduce.
Using this Webpack config:
module.exports = {
mode: 'none',
externals: {
'amd-module': { amd: 'amd-module' }
}
}
Transpiling the code require('amd-module') results in a dependency like this being included in the output:
/* 1 */
/***/ (function(module, exports) {
module.exports = undefined;
/***/ })
What is the expected behavior?
Given any AMD dependency and no libraryTarget, I would expect one of the following outcomes:
- The output is surrounded by a
require(...)orrequirejs(...)wrapper, much as is done already withdefine(...)whenlibraryTarget: 'amd'is set. - A build-time error is shown about the unresolved dependency, as is already done if
libraryTarget: 'umd'is set. Adding that to the above config results in a build error "Missing external configuration for type:commonjs2". In this case I would also expect a mention in the docs about this incompatibility.
The current behaviour of leaving the dependency as undefined is surprising and hard to debug.
Other relevant information: webpack version: 4.19.1
Previously reported bugs #4609 and #6302 have touched on some aspects of this issue, but have not provided a workable solution for the case when the external dependency is only available via AMD and the target is not a library.