Javascript React项目中引导所需的jQuery

Javascript React项目中引导所需的jQuery,javascript,jquery,reactjs,twitter-bootstrap-3,Javascript,Jquery,Reactjs,Twitter Bootstrap 3,我正在开发一个React.js项目,在这个项目中,我没有使用React Bootstrap,而是将Bootstrap的CSS加载到我的项目中。我现在需要导入jQuery,以便使用下拉菜单等 入口点文件(index.js)-希望它能工作 'use strict' import React from 'react' import { Route, Router, IndexRoute, browserHistory } from 'react-router' import { render } fr

我正在开发一个React.js项目,在这个项目中,我没有使用React Bootstrap,而是将Bootstrap的CSS加载到我的项目中。我现在需要导入jQuery,以便使用下拉菜单等

入口点文件(index.js)-希望它能工作

'use strict'
import React from 'react'
import { Route, Router, IndexRoute, browserHistory } from 'react-router'
import { render } from 'react-dom'

// Pages
import Main from './pages/main/main'
import Home from './pages/home/home'
import About from './pages/about/about'
window.jQuery = window.$ = require('jquery/dist/jquery.min')
import '../node_modules/bootstrap/dist/css/bootstrap.min.css'
import '../node_modules/bootstrap/dist/js/bootstrap.min.js'

render((
  <Router history={browserHistory}>
    <Route name='home' path='/' component={Main}>
      <IndexRoute component={Home} />
      <Route name='about' path='about' component={About} />
    </Route>
  </Router>), document.getElementById('app'))

错误出现在Chrome开发工具中:“Bootstrap的Javascript需要jQuery”。我想知道我是否在网页包文件中缺少加载程序方面的内容,或者在条目文件中需要导入语句?

请确保您已安装“导入加载程序”(npm安装--保存导入加载程序)。在module.exports中,请尝试以下操作:

{ test: /bootstrap.+\.(jsx|js)$/, loader: 'imports?jQuery=jquery,$=jquery,this=>window' }

我在这里找到了一篇非常好的帖子:

不幸的是,提供的解决方案不适合我。在上述情况下,Bootstrap和jQuery都作为npm依赖项安装在node_modules目录下?我使用的是WebPack 2,因此我将loader元素转换为:

{
        test: /bootstrap.+\.(jsx|js)$/,
        use: 'imports-loader?jQuery=jquery,$=jquery,this=>window',
        exclude: /node_modules/
}

尝试将您的jquery导入移动到Web包文件中的babel-loader上方。错误仍然存在。在my package.json中-“jquery”:“^3.0.0”是否有帮助?
{
        test: /bootstrap.+\.(jsx|js)$/,
        use: 'imports-loader?jQuery=jquery,$=jquery,this=>window',
        exclude: /node_modules/
}