javascript - Dynamic import from node_modules throws "Cannot read property 'call' of undefined"
问题描述
Webpack-stream version: 5.2.1
npm version: 6.14.4
node version: v10.13.0
platform: windows10
I use gulp + webpack-stream for two modules: libraries.js and page.js
The problem relates only to the import from node_modules to page.js, the same import to libraries.js works well.
Import module as
import 'slick-carousel/slick/slick';
and even just import throws that error without call
Full code page.js
'use strict';
import '../_modules/forms/doctor-review';
import 'slick-carousel/slick/slick';
$(window).on('load', function () {
$('.js-slick').slick();
});
webpack config for libraries.js:
{
mode: λ.mode,
output: {
pathinfo: false,
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
optimization: {
splitChunks: {
cacheGroups: {
default: false,
vendors: false,
vendor: {
chunks: 'all',
test: /node_modules/,
},
},
},
},
}
webpack config for page.js:
{
mode: λ.mode,
output: {
pathinfo: false,
},
plugins: [],
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
optimization: {
namedModules: true,
namedChunks: true,
splitChunks: {
cacheGroups: {
default: false,
vendors: false,
vendor: {
chunks: 'all',
test: /node_modules/,
},
},
},
},
}
解决方案
推荐阅读
- python - 找到一组对的最大总重量
- python-3.x - TypeError:“Word2Vec”对象不可下标
- ssh - 试图获取 kubernetes 节点的 ssh
- woocommerce - Woocommerce:显示 0 定价可变产品的正常价格
- azure - Azure 数据工厂在我有权限时在 SFTP 上给出拒绝访问错误
- python-3.7 - 以纳秒为单位的 Python 格式日期
- ios - Xcode Memory Graph 报告释放对象的泄漏
- android - 如何自动化 Flutter 应用程序
- c++ - 是否需要从 C++ 中的调用函数恢复协程?
- r - 为 r 中的核密度估计图 (density.ppp) 选择像素大小