ama*_*put 10 javascript node-modules reactjs npm-install npm-start
我正在做一个 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.
Run Code Online (Sandbox Code Playgroud)
我找到了很多解决方案,我也尝试过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
Run Code Online (Sandbox Code Playgroud)
gek*_*dev 18
确保您@babel/runtime安装的是常规版本dependencies,而不是devDependencies(安装时省略--dev或-D标志)。
npm i @babel/runtime
Run Code Online (Sandbox Code Playgroud)
或者
yarn add @babel/runtime
Run Code Online (Sandbox Code Playgroud)
否则在进行生产安装时它会丢失(省略了该devDependencies部分),这就是我身上发生的事情。
在大多数情况下,所有提供的答案都是正确的,但我想添加一个解释:Babel 的运行时是与代码一起提供的生产运行时,因此不能因为它在客户端上运行而将其排除在外。
我找到了解决方案
npm install --save-exact @babel/runtime@7.0.0-beta.55
然后删除 package-json.lock 文件和 node_modules 文件夹,然后用npm install重新安装
这个对我有用。
嘿 !试试这个,它对我有用... :)
使用 npm:
npm install --save @babel/runtime
使用纱线:
yarn add @babel/runtime
快乐编码!
对我来说,我通过添加 .js 和 .jsx 作为可解析扩展来解决这个问题,因为 objectWithoutPropertiesLoose 没有扩展名。
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"]
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15614 次 |
| 最近记录: |