[英]Module not found: Can't resolve '@material-ui/core/Container'
In the browser, I get the error在浏览器中,我收到错误消息
Failed to compile Module not found: Can't resolve '@material-ui/core/Container'
无法编译找不到模块:无法解析“@material-ui/core/Container”
It's looking for the component inside of my components directory instead of node_modules.它正在我的组件目录中寻找组件,而不是 node_modules。 I can't change directories into node_modules
../../
because node_modules is outside of src
directory and Create React App won't let me.我无法将目录更改为 node_modules
../../
因为 node_modules 在src
目录之外,并且 Create React App 不允许我这样做。
I've use yarn to remove and $ yarn add @material-ui/core
.我已经使用 yarn 来移除和
$ yarn add @material-ui/core
。 I've tried yarn run build which gives me the error我试过 yarn run build 这给了我错误
Cannot find module: '@material-ui/core/Container'.
找不到模块:'@material-ui/core/Container'。 Make sure this package is installed.
确保已安装此软件包。 You can install this package by running: yarn add @material-ui/core/Container.
你可以通过运行安装这个包:yarn add @material-ui/core/Container。
When I try to add it, I get the error当我尝试添加它时,我得到了错误
error Couldn't find package "@material-ui/core/Container" on the "npm" registry.
错误在“npm”注册表中找不到包“@material-ui/core/Container”。
Here's the dependencies I have that are related:这是我拥有的相关依赖项:
"@material-ui/core": "^3.9.3",
"@material-ui/icons": "^3.0.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
I expect to see the contents of the page not take up the full width of the screen, but instead, I receive a fail to compile error.我希望看到页面的内容不会占据屏幕的整个宽度,而是收到一个编译失败错误。
Container
is not part of the material-ui
version specified in your package.json
. Container
不是package.json
中指定的material-ui
版本的一部分。
To upgrade, run the following:要升级,请运行以下命令:
$ yarn add @material-ui/core@next
You might have to remove the old stable version (if that's even an option for you).您可能必须删除旧的稳定版本(如果这甚至是您的选择)。
React and react-dom >= 16.8.0 are all that are needed as peer dependencies, so the experimental upgrade of material-ui
should be all you need to use Container
.需要 React 和 react-dom >= 16.8.0 作为对等依赖项,所以使用
Container
应该只需要对material-ui
进行实验性升级。
I had a similar issue and I resolved it by calling:我有一个类似的问题,我通过调用解决了它:
for npm:对于 npm:
npm install @material-ui/core
for yarn:对于纱线:
$ yarn add @material-ui/core@next
If you follow a npx create-react-app new-app
with cd new-app
and yarn add @material-ui/core
it wile compile with yarn start
.如果您使用
cd new-app
和yarn add @material-ui/core
跟随npx create-react-app new-app
,它会使用yarn start
进行编译。 You might try just starting over.您可以尝试重新开始。
However, to help your troubleshooting, this error typically happens when you try to use a Material-UI component and forget to import it.但是,为了帮助您进行故障排除,当您尝试使用 Material-UI 组件并忘记导入它时,通常会发生此错误。 Have you tried commenting out all the code and seeing if it compiles?
您是否尝试过注释掉所有代码并查看它是否可以编译?
This error might also indicate that there are no node_modules for what is being imported.此错误还可能表明正在导入的内容没有 node_modules。 So,
npm install
might solve the problem.所以,
npm install
可能会解决这个问题。
只需安装: npm install @material-ui/core
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.