【问题标题】:How to fix - Module not found: Can't resolve '@babel/runtime/helpers/objectWithoutPropertiesLoose'如何修复 - 找不到模块:无法解析 '@babel/runtime/helpers/objectWithoutPropertiesLoose'
【发布时间】:2020-01-04 07:54:45
【问题描述】:

我正在做一个 react 项目,在实现这个包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

【问题讨论】:

    标签: javascript reactjs node-modules npm-install npm-start


    【解决方案1】:

    嘿?!试试这个,它对我有用... :)

    ? 使用 npm:

    npm install --save @babel/runtime

    ? 使用纱线:

    yarn add @babel/runtime

    ? 编码快乐!

    【讨论】:

      【解决方案2】:

      确保将@babel/runtime 安装到常规dependencies 而不是devDependencies(安装时省略--dev-D 标志)。

      npm i @babel/runtime
      

      yarn add @babel/runtime
      

      否则在进行生产安装时它会丢失(省略了devDependencies 部分),这就是发生在我身上的事情。

      在大多数情况下,所有提供的答案都是正确的,但我想添加一个解释: Babel 的运行时是 a production runtime that ships with your code,所以不能因为它运行在客户端上而被忽略。

      【讨论】:

        【解决方案3】:

        对我来说,我通过添加 .js 和 .jsx 作为可解析扩展来解决这个问题,因为 objectWithoutPropertiesLoose 没有扩展。

        resolve: {
                extensions: [".ts", ".tsx", ".js", ".jsx"]
        },
        

        【讨论】:

        • 你把那个放在哪里了?
        • webpack.config.js 导出
        【解决方案4】:

        我找到了解决办法

        npm install --save-exact @babel/runtime@7.0.0-beta.55

        然后删除 package-json.lock 文件和 node_modules 文件夹,然后使用 npm install

        重新安装

        它对我有用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-01-14
          • 2021-11-14
          • 2022-12-13
          • 2016-03-23
          • 1970-01-01
          • 2021-11-18
          • 2021-05-29
          • 2019-06-21
          相关资源
          最近更新 更多