![](/img/trans.png)
[英]Bootstrap and Javascript conflict issue in Visual Studio 2017
[英]Bootstrap error "jQuery is not defined" in Visual Studio 2017 react/redux project
有很多關於此錯誤的文檔,但對於使用 Visual Studio 的非 webpack/人員似乎沒有任何答案。
我已經嘗試了所有與 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 未定義 ./node_modules/bootstrap/js/dropdown.js
我也試過在 app 組件上導入 dropdown.js 但仍然沒有。
它似乎是一個webpack 問題,但 Visual Studio 沒有 webpack 配置文件,所以我也無法嘗試任何這些修復。 我不確定 Visual Studio 是否在幕后使用 webpack
有沒有人遇到過這個問題?
嘗試移動(window as any).jQuery = $;
上面的行import '../node_modules/bootstrap/js/dropdown.js';
.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.