簡體   English   中英

如何修復 - 找不到模塊:無法解析 '@babel/runtime/helpers/objectWithoutPropertiesLoose'

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM