[英]How to fix - Module not found: Can't resolve '@babel/runtime/helpers/objectWithoutPropertiesLoose'
I am working on a project of react and I am getting the following error after implement this package https://www.npmjs.com/package/react-bootstrap-typeahead then i get the following error.我正在研究一个反应项目,在实施此包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.
I found many solutions and I tried it too https://github.com/jquense/yup/issues/216 but still getting same error.我找到了很多解决方案,我也尝试过https://github.com/jquense/yup/issues/216但仍然遇到同样的错误。
But when i remove Typeahead component then it works fine.但是当我删除 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
You can install @babel/runtime
to fix the problem:你可以安装@babel/runtime
来解决这个问题:
Using npm:使用 npm:
npm install --save @babel/runtime
Using yarn:使用纱线:
yarn add @babel/runtime
I found a solution我找到了解决方案
npm install --save-exact @babel/runtime@7.0.0-beta.55
Then delete the package-json.lock
file and node_modules
folder then re-install with npm install
.然后删除package-json.lock
文件和node_modules
文件夹,然后使用npm install
重新安装。
It works for me.这个对我有用。
Make sure you got @babel/runtime
installed into your regular dependencies
and not the devDependencies
(leave out the --dev
or the -D
flag when installing).确保您已将@babel/runtime
安装到常规dependencies
项中,而不是devDependencies
(安装时--dev
或-D
标志)。
npm i @babel/runtime
OR或者
yarn add @babel/runtime
Else it's going to be missing when doing a production installation (which leaves out the devDependencies
section), which is what happened to me.否则在进行生产安装时它会丢失(省略了devDependencies
部分),这就是发生在我身上的事情。
All provided answers are correct in most cases but I wanted to add an explanation: Babel's runtime is a production runtime that ships with your code so it can't just be left out because it runs on the client.在大多数情况下,所有提供的答案都是正确的,但我想添加一个解释:Babel 的运行时是随您的代码一起提供的生产运行时,因此不能因为它在客户端上运行而忽略它。
For me, i solve this by adding .js and .jsx as a resolvable extensions as objectWithoutPropertiesLoose is without extension.对我来说,我通过添加 .js 和 .jsx 作为可解析的扩展来解决这个问题,因为 objectWithoutPropertiesLoose 没有扩展。
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"]
},
You can try the following solution 您可以尝试以下解决方案
To install it, you can run: npm install --save @babel/runtime/helpers/builtin/objectWithoutPropertiesLoose
OR 要么
npm add @babel/runtime
Hope it works for you . 希望对你有效 。
For me, I have to use these configurations on my webpack.config.js file对我来说,我必须在我的 webpack.config.js 文件中使用这些配置
module: {
rules: [
{
test: /\.m?js/,
resolve: { fullySpecified: false },
},
],
}
I know this is an old issue, but it may help someone else我知道这是一个老问题,但它可能对其他人有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.