简体   繁体   English

如何修复错误; '错误:Bootstrap工具提示需要Tether(http://github.hubspot.com/tether/)'

[英]How to fix the error; 'Error: Bootstrap tooltips require Tether (http://github.hubspot.com/tether/)'

I'm using Bootstrap V4 and the following error is logged in the console; 我正在使用Bootstrap V4,并在控制台中记录以下错误;

Error: Bootstrap tooltips require Tether ( http://github.hubspot.com/tether/ ) 错误:Bootstrap工具提示需要Tether( http://github.hubspot.com/tether/

I have tried to remove the error by installing Tether but it hasn't worked. 我试图通过安装Tether删除错误,但它没有奏效。 I have 'installed' Tether by including the following lines of code; 我通过包含以下代码行“安装”了Tether;

<link rel="stylesheet" href="http://www.atlasestateagents.co.uk/css/tether.min.css">
<script src="http://www.atlasestateagents.co.uk/javascript/tether.min.js"></script>

Have I 'installed' tether correctly? 我是否正确安装了系绳?

Can anyone help me remove this error? 任何人都可以帮我删除此错误?

If you wish to view the error on my site, please click here and load your console. 如果您希望在我的网站上查看错误,请单击此处并加载您的控制台。

For Bootstrap 4 stable: 对于Bootstrap 4稳定:

Since beta Bootstrap 4 doesn't depend on Tether but Popper.js . 因为beta Bootstrap 4不依赖于Tether而是依赖于Popper.js All scripts ( must be in this order): 所有脚本( 必须按此顺序):

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>

See the current documentation for the newest script versions. 有关最新脚本版本,请参阅当前文档


Only Bootstrap 4 alpha: 只有Bootstrap 4 alpha:

Bootstrap 4 alpha needs Tether , so you need to include tether.min.js before you include bootstrap.min.js , eg. Bootstrap 4 alpha需要Tether ,因此包含bootstrap.min.js 之前需要包含tether.min.js

<script src="https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js"></script>
<script src="https://npmcdn.com/bootstrap@4.0.0-alpha.5/dist/js/bootstrap.min.js"></script>

If you're using Webpack: 如果您使用的是Webpack:

  1. Set up bootstrap-loader as described in docs; 按文档中的描述设置bootstrap-loader;
  2. Install tether.js via npm; 通过npm安装tether.js;
  3. Add tether.js to the webpack ProvidePlugin plugin. 将tether.js添加到webpack ProvidePlugin插件中。

webpack.config.js: webpack.config.js:

plugins: [
        <... your plugins here>,
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery",
            "window.Tether": 'tether'
        })
    ]

Source 资源

If you are using npm and browserify: 如果您使用的是npm和browserify:

// es6 imports
import tether from 'tether';
global.Tether = tether;

// require
global.Tether = require('tether');

Personally I use small subset of Bootstrap functionality and don't need to attach Tether. 我个人使用Bootstrap功能的小子集,不需要附加Tether。

This should help: 这应该有所帮助:

window.Tether = function () {
  throw new Error('Your Bootstrap may actually need Tether.');
};

If you want to avoid the error message and you are not using Bootstrap tool tips, you can define window.Tether before loading Bootstrap. 如果要避免出现错误消息并且未使用Bootstrap工具提示,则可以在加载Bootstrap之前定义window.Tether。

<script>
  window.Tether = {};
</script>
<script src="js/bootstrap.min.js"></script>

You should done my guideline: 你应该完成我的指导方针:
1. Add bellow source into Gemfile 1.将波纹管源添加到Gemfile中

source 'https://rails-assets.org' do
  gem 'rails-assets-tether', '>= 1.1.0'
end
  1. Run command: 运行命令:

    bundle install 捆绑安装

  2. Add this line after jQuery in application.js. 在application.js中的jQuery之后添加这一行。

    //= require jquery // =需要jquery
    //= require tether // =需要系绳

  3. Restart rails server. 重启rails服务器。

Install tether via npm like below 如下所示,通过npm安装系绳

npm install tether --save-dev

then add tether to your html above bootstrap like below 然后将tether添加到你的html上面的bootstrap,如下所示

<script src="node_modules/tether/dist/js/tether.min.js"></script>
<script src="jspm_packages/github/twbs/bootstrap@4.0.0-alpha.2/js/bootstrap.js"></script>

For webpack I resolved this with webpack.config.js : 对于webpack,我用webpack.config.js解决了这个webpack.config.js

new webpack.ProvidePlugin({
  $: 'jquery',
  jQuery: 'jquery',
  "window.jQuery": "jquery",
  Tether: 'tether'
})

An additional note. 另外一个说明。 If you check uncompressed javascript file, you will find the condition: 如果您检查未压缩的javascript文件,您将找到以下条件:

if(window.Tether === undefined) {
     throw new Error('Bootstrap tooltips require Tether (http://github.hubspot.com/tether)')
}

So the error message contains the required information. 因此错误消息包含所需的信息。

You can download the archive from that link . 您可以从该链接下载存档。

Uncompressed version: 未压缩版本:

https://rawgit.com/HubSpot/tether/master/src/js/tether.js https://rawgit.com/HubSpot/tether/master/dist/css/tether.css https://rawgit.com/HubSpot/tether/master/src/js/tether.js https://rawgit.com/HubSpot/tether/master/dist/css/tether.css

Using webpack I used this in webpack.config.js : 使用webpack我在webpack.config.js使用了这个:

var plugins = [

    ...

    new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        'window.jQuery': 'jquery',
        'window.Tether': 'tether',
        tether: 'tether',
        Tether: 'tether'
    })
];

It seems like Tether was the one it was looking for: 似乎Tether是它正在寻找的那个:

var Tooltip = function ($) {

  /**
   * Check for Tether dependency
   * Tether - http://tether.io/
   */
  if (typeof Tether === 'undefined') {
    throw new Error('Bootstrap tooltips require Tether (http://tether.io/)');
  }

I was having this issue with requirejs using the newest boostrap 4 build. 我在使用最新的boostrap 4版本的requirejs时遇到了这个问题。 I ended up just defining: 我最后定义了:

<script>
  window.Tether = {};
</script>

in my html head tag to fool bootstrap's check. 在我的html head标签中愚弄bootstrap的检查。 I then added a second require statement just before the require that loads my app, and subsequently, my bootstrap dependency: 然后我在加载我的应用程序的require之前添加了第二个require语句,随后我的bootstrap依赖项:

require(['tether'], function (Tether) {
  window.Tether = Tether;
});

require([
  "app",
], function(App){
  App.initialize();
});

Using both of these in tandem and you should have no problem using current bootstrap 4 alpha build. 同时使用这两者并使用当前的bootstrap 4 alpha版本应该没有问题。

Works for generator-aspnetcore-spa and bootstrap 4. 适用于generator-aspnetcore-spa和bootstrap 4。

// ===== file: webpack.config.vendor.js =====    
module.exports = (env) => {
...
    plugins: [
        new webpack.ProvidePlugin({ $: 'jquery', 
                                    jQuery: 'jquery',
                                    'window.jQuery': 'jquery',
                                    'window.Tether': 'tether',
                                    tether: 'tether', 
                                    Tether: 'tether' }), 
// Maps these identifiers to the jQuery package 
// (because Bootstrap expects it to be a global variable)
            ...
        ]
};

For webpack 1 or 2 with Bootstrap 4 you need 对于带有Bootstrap 4的webpack 1或2,您需要

new webpack.ProvidePlugin({
   $: 'jquery',
   jQuery: 'jquery',
   Tether: 'tether'
})

If you are using Brunch, you can add this at the end of your brunch-config.js : 如果您使用Brunch,可以在brunch-config.js的末尾添加:

npm: {
    enabled: true,
    globals: {
        $: 'jquery', jQuery: 'jquery', 'Tether': 'tether'
    }
}

If you use require.js AMD loader: 如果你使用require.js AMD加载器:

// path config
requirejs.config({
  paths: {
    jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/core.js',
    tether: '//cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min',
    bootstrap: '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min',
  },
  shim: {
    bootstrap: {
      deps: ['jquery']
    }
  }
});

//async loading
requirejs(['tether'], function (Tether) {
  window.Tether = Tether;
  requirejs(['bootstrap']);
});

For you Laravel Mix users out there running Bootstrap4, you will need to run 对于运行Bootstrap4的Laravel Mix用户,您需要运行

npm installer tether --save

Then update you resources/assets/js/bootstrap.js to load Tether and bring it to the window object. 然后更新resources/assets/js/bootstrap.js以加载Tether并将其带到window对象。

Here is what mine looks like: (Note I also had to run npm install popper.js --save ) 这是我的样子:(注意我还必须运行npm install popper.js --save

window.$ = window.jQuery = require('jquery');
window.Popper = require('popper.js').default;
window.Tether = require('tether');
require('bootstrap');

UMD/AMD solution UMD / AMD解决方案

For those guys, who are doing it through UMD , and compile via require.js , there is a laconic solution. 对于那些通过UMD进行的人 ,并通过require.js编译,有一个简洁的解决方案。

In the module, which requires tether as the dependency, which loads Tooltip as UMD, in front of module definition, just put short snippet on definition of Tether: 在模块中,需要tether作为依赖关系,它将Tooltip作为UMD加载,在模块定义之前,只需在tether的定义上添加简短的片段:

// First load the UMD module dependency and attach to global scope
require(['tether'], function(Tether) {
    // @todo: make it properly when boostrap will fix loading of UMD, instead of using globals
    window.Tether = Tether; // attach to global scope
});

// then goes your regular module definition
define([
    'jquery',
    'tooltip',
    'popover'
], function($, Tooltip, Popover){
    "use strict";
    //...
    /*
        by this time, you'll have window.Tether global variable defined,
        and UMD module Tooltip will not throw the exception
    */
    //...
});

This short snippet at the very beginning, actually may be put on any higher level of your application, the most important thing - to invoke it before actual usage of bootstrap components with Tether dependency. 这个简短的片段在一开始,实际上可以放在应用程序的任何更高级别,最重要的是 - 在实际使用具有Tether依赖性的bootstrap组件之前调用它。

// ===== file: tetherWrapper.js =====
require(['./tether'], function(Tether) {
    window.Tether = Tether; // attach to global scope
    // it's important to have this, to keep original module definition approach
    return Tether;
});

// ===== your MAIN configuration file, and dependencies definition =====
paths: {
    jquery: '/vendor/jquery',
    // tether: '/vendor/tether'
    tether: '/vendor/tetherWrapper'  // @todo original Tether is replaced with our wrapper around original
    // ...
},
shim: { 
     'bootstrap': ['tether', 'jquery']       
}

UPD: In Boostrap 4.1 Stable they replaced Tether , with Popper.js , see the documentation on usage . UPD:在自举4.1稳定他们取代系绳 ,与Popper.js ,看到上使用的文档

To add to @adilapapaya's answer. 添加到@ adilapapaya的答案。 For ember-cli users specifically, install tether with 对于ember-cli用户,请安装tether

bower install --save tether

and then include it in your ember-cli-build.js file before bootstrap, like so: 然后在bootstrap之前将它包含在你的ember-cli-build.js文件中,如下所示:

// tether (bootstrap 4 requirement)
app.import('bower_components/tether/dist/js/tether.min.js');

// bootstrap
app.import('bower_components/bootstrap/scss/bootstrap-flex.scss');
app.import('bower_components/bootstrap/dist/js/bootstrap.js');

And if using webpack, you will need the expose plugin. 如果使用webpack,则需要使用公开插件。 In your webpack.config.js, add this loader 在webpack.config.js中,添加此加载器

{
   test: require.resolve("tether"),
   loader: "expose?$!expose?Tether"
}

I had the same problem and this is how I solved it. 我有同样的问题,这就是我解决它的方式。 I'm on rails 5.1.0rc1 我在轨道5.1.0rc1上

Make sure to add require jquery and tether inside your application.js file they must be at the very top like this 确保在application.js文件中添加require jquery和tether,它们必须位于最顶端

//= require jquery
//= require tether

Just make sure to have tether installed 只要确保安装了系绳

Method #1 : Download from Here and insert it to your projects, or 方法#1 :从这里下载并将其插入您的项目,或
Method #2 : use below code before your bootstrap script source: 方法#2 :在引导脚本源之前使用下面的代码:

<script src="https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js"></script>

I recommend following the instructions in the Bootstrap 4 documentation : 我建议按照Bootstrap 4文档中的说明进行操作:

Copy-paste the stylesheet <link> into your <head> before all other stylesheets to load our CSS. 在所有其他样式表之前将样式表<link>复制粘贴到<head>以加载CSS。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">

Add our JavaScript plugins, jQuery, and Tether near the end of your pages, right before the closing tag. 在结束标记之前,在页面末尾添加我们的JavaScript插件,jQuery和Tether。 Be sure to place jQuery and Tether first, as our code depends on them. 一定要先放置jQuery和Tether,因为我们的代码依赖于它们。 While we use jQuery's slim build in our docs, the full version is also supported. 虽然我们在文档中使用jQuery的slim版本,但也支持完整版本。

<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

I had the same problem and i solved it by including jquery-3.1.1.min before including any js and it worked like a charm. 我有同样的问题,我通过包括jquery-3.1.1.min解决它之前包括任何js,它就像一个魅力。 Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决错误; “ SyntaxError:标识符&#39;getScrollParents&#39;已经被声明;引导工具提示需要Tether; - How to fix the Error; "SyntaxError: Identifier 'getScrollParents' has already been declared; Bootstrap tooltips require Tether; 捆绑Bootstrap 4 - Bootstrap工具提示需要Tether - Bundling Bootstrap 4 - Bootstrap tooltips require Tether 安装 MailChimp 弹出 js 时,我收到 Uncaught Error: Bootstrap tooltips require Tether 和 Uncaught ReferenceError: Cookies is not defined - When installing MailChimp pop-up js I get Uncaught Error: Bootstrap tooltips require Tether and Uncaught ReferenceError: Cookies is not defined webpack如何要求系绳? - How to require tether with webpack? 如何在没有Tether的情况下添加Bootstrap 4? - How to add Bootstrap 4 without Tether? Bootstrap 4系绳放置 - Bootstrap 4 tether placements 使用ng-repeat和limit-to以及来自tether.js的工具提示时,在jQuery中获取上下文错误 - Getting an error with context in jQuery when using ng-repeat and limit-to and a tooltip from tether.js webpack:系绳未定义 - webpack: Tether is not defined 工具提示与requireJS绑定 - Tooltip Tether with requireJS 如何在Tether.js / drop.js中使用React Component - How to use React Component with Tether.js/drop.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM