![](/img/trans.png)
[英]How to solve Module not found: Can't resolve '@babel/runtime/core-js/map' in Material-UI
[英]How to fix - Module not found: Can't resolve '@babel/runtime/helpers/objectWithoutPropertiesLoose'
我正在研究一个反应项目,在实施此包https://www.npmjs.com/package/react-bootstrap-typeahead后出现以下错误,然后出现以下错误。
Failed to compile
./node_modules/react-popper/lib/cjs/Popper.js
Module not found: Can't resolve '@babel/runtime/helpers/objectWithoutPropertiesLoose' in 'E:\reactjs\deveans-react-version\node_modules\react-popper\lib\cjs'
This error occurred during the build time and cannot be dismissed.
我找到了很多解决方案,我也尝试过https://github.com/jquense/yup/issues/216但仍然遇到同样的错误。
但是当我删除 Typeahead 组件时,它工作正常。
import React , { Component } from 'react'
import {Typeahead} from 'react-bootstrap-typeahead';
import 'react-bootstrap-typeahead/css/Typeahead.css';
class States extends Component {
state = {
multiple: false,
options: [
{id: 1, label: 'Pakistan'},
{id: 2, label: 'Indonesia'},
{id: 3, label: 'Turkey'},
{id: 4, label: 'Brazil'},
]
};
render () {
const {multiple} = this.state;
return (
<div>
<Typeahead
labelKey="label"
multiple={multiple}
options={this.state.options}
placeholder="Choose a state..."
/>
</div>
)
}
}
export default States
你可以安装@babel/runtime
来解决这个问题:
使用 npm:
npm install --save @babel/runtime
使用纱线:
yarn add @babel/runtime
我找到了解决方案
npm install --save-exact @babel/runtime@7.0.0-beta.55
然后删除package-json.lock
文件和node_modules
文件夹,然后使用npm install
重新安装。
这个对我有用。
确保您已将@babel/runtime
安装到常规dependencies
项中,而不是devDependencies
(安装时--dev
或-D
标志)。
npm i @babel/runtime
或者
yarn add @babel/runtime
否则在进行生产安装时它会丢失(省略了devDependencies
部分),这就是发生在我身上的事情。
在大多数情况下,所有提供的答案都是正确的,但我想添加一个解释:Babel 的运行时是随您的代码一起提供的生产运行时,因此不能因为它在客户端上运行而忽略它。
对我来说,我通过添加 .js 和 .jsx 作为可解析的扩展来解决这个问题,因为 objectWithoutPropertiesLoose 没有扩展。
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"]
},
您可以尝试以下解决方案
To install it, you can run: npm install --save @babel/runtime/helpers/builtin/objectWithoutPropertiesLoose
要么
npm add @babel/runtime
希望对你有效 。
对我来说,我必须在我的 webpack.config.js 文件中使用这些配置
module: {
rules: [
{
test: /\.m?js/,
resolve: { fullySpecified: false },
},
],
}
我知道这是一个老问题,但它可能对其他人有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.