gpt4 book ai didi

jquery - Visual Studio 2017 react/redux 项目中的 Bootstrap 错误 "jQuery is not defined"

转载 作者:搜寻专家 更新时间:2023-10-30 21:47:36 25 4
gpt4 key购买 nike

关于这个错误有很多文档,但对于非 webpack/使用 Visual Studio 的人似乎没有任何答案。

我已经尝试了所有非 webpack 相关的错误,例如在窗口上声明 jQuery,但似乎没有任何效果,我的 index.tsx 文件在下面。

import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';
import * as $ from 'jquery';
import 'popper.js';
import '../node_modules/bootstrap/js/dropdown.js';
import './styles/Site.css'
import * as React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { BrowserRouter, Route } from 'react-router-dom';
import configureStore from './store/configureStore';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

(window as any).jQuery = $;
(window as any).$ = $;

const store = configureStore();

render(
<BrowserRouter>
<Provider store={store}>
<Route path="/" component={App} />
</Provider>
</BrowserRouter>,
document.getElementById('root'));

registerServiceWorker();

加载时出现错误

ReferenceError: jQuery is not defined ./node_modules/bootstrap/js/dropdown.js

我也试过在应用程序组件上导入 dropdown.js 但仍然没有。

它看起来确实是一个 webpack issue但是 Visual Studio 没有 webpack 配置文件,所以我也不能尝试任何这些修复。我不确定 Visual Studio 是否在幕后使用了 webpack

有没有人遇到过这个问题?

最佳答案

尝试将 (window as any).jQuery = $; 行移至 import '../node_modules/bootstrap/js/dropdown.js'; 上方。/p>

关于jquery - Visual Studio 2017 react/redux 项目中的 Bootstrap 错误 "jQuery is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52080777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com