本文介绍了在 webpack.config 中定义的外部仍然找不到错误模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 webpack.config 中为 material-ui 定义了 externals
I have defined externals in webpack.config for material-ui
module.exports = [{
entry: ...
output:...
externals: {
react: {
commonjs: "react",
commonjs2: "react"
},
"material-ui": {
commonjs: "material-ui",
commonjs2: "material-ui"
}
},
module: ...
}];
仍然给出错误,如 -
Still its giving error like-
无法解析模块'material-ui/IconButton'......
在我的入口js文件中,我有
In my entry js file, I have
import React, {Component} from "react";
import IconButton from "material-ui/IconButton";
.....
.....
推荐答案
好的,我解决了.外部需要完整路径.
Ok I solved it. External expects complete path.
所以,
import {IconButton} from "material-ui"
或
externals: {
"material-ui/IconButton": {
commonjs: "material-ui/IconButton",
...
}
}
会起作用.当然,这里的第二种选择是不合理的
will work. Ofcourse, second option is not reasonable here
这篇关于在 webpack.config 中定义的外部仍然找不到错误模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!