webpack.config 中定义的外部仍然出现错误模块未找到

Externals defined in webpack.config still getting error module not found

我在 webpack.config 中为 material-ui

定义了外部变量
module.exports = [{
  entry: ...
  output:...
  externals: {
    react: {
      commonjs: "react",
      commonjs2: "react"
    },
    "material-ui": {
      commonjs: "material-ui",
      commonjs2: "material-ui"
    }
  },
  module: ...
}];

仍然给出错误,如-

Cannot resolve module 'material-ui/IconButton'......

在我的入口js文件中,我有

import React, {Component} from "react";
import IconButton from "material-ui/IconButton";
.....
.....

好的,我解决了。外部需要完整路径。

所以,

import {IconButton} from "material-ui"

externals: {
  "material-ui/IconButton": {
    commonjs: "material-ui/IconButton",
    ...
  }
}

会起作用。当然,第二个选项在这里是不合理的