简体   繁体   English

Webpack无法加载bootstrap v4.0.0-beta

[英]Webpack fails to load bootstrap v4.0.0-beta

I've recently made a config with webpack and bootstrap v4.0.0-alpha.6 which worked fine until today when I tried to change to v4 beta and now I can't seem to make it work properly :( I have this config: 我最近使用webpack和bootstrap v4.0.0-alpha.6进行了配置工作正常,直到今天我尝试更改为v4测试版,现在我似乎无法使其正常工作:(我有这个配置:

webpack.config.js webpack.config.js

entry: {
    app: "./src/app.js"
},
output: {
    path: path.resolve(__dirname, 'public'),
    filename: 'js/[name].js',
    hotUpdateChunkFilename: 'hot/hot-update.js',
    hotUpdateMainFilename: 'hot/hot-update.json'
},
module: {
    loaders: [
        { test: /\.js$/, exclude: /node-modules/, loader: 'babel-loader' },
        { test: /\.html$/, loader: 'raw-loader', exclude: /node_modules/ },
        {   test: /\.(css|scss|sass)$/,
            loader: ExtractTextPlugin.extract({
                fallback: "style-loader",
                use: ['css-loader', 'postcss-loader', 'sass-loader']
            }),
            exclude: /node_modules/
        }           
    ]
},
plugins: [
    new webpack.ProvidePlugin({ // inject ES5 modules as global vars
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        Popper: ['popper.js', 'default']
    }),
    new ExtractTextPlugin('/css/[name].css'),

in my app.js I have the require('bootstrap'); 在我的app.js中我有require('bootstrap'); Now when I try to make build now I get an error: 现在,当我尝试进行构建时,我收到一个错误:

ERROR in ./node_modules/bootstrap/dist/js/bootstrap.js
Module build failed: ReferenceError: Unknown plugin "transform-es2015-modules-strip" specified in "E:\\Documente\\Work\\wordpress\\wordpressSite\\wp-content\\themes\\bsTheme\\node_modules\\bootstra
p\\.babelrc" at 0, attempted to resolve relative to "E:\\Documente\\Work\\wordpress\\wordpressSite\\wp-content\\themes\\bsTheme\\node_modules\\bootstrap"

The issue seems to be here in bootstrap/.babelrc 问题似乎在bootstrap/.babelrc

{
    "presets": [
        [
            "es2015",
            {
                "loose": true,
                "modules": false
            }
        ]
    ],
    "plugins": [
        "transform-es2015-modules-strip"
    ]
}

I tried to go in bootstrap directory and ran: npm install (i don't know why I should do that since I already have my own config for bable/autoprefixer) I already have babel-core, babel-loader, babel-preset-es2015 installed in my own package.json I installed transform-es2015-modules-strip and ran build again: 我试着进入bootstrap目录并运行: npm install (我不知道为什么我应该这样做,因为我已经拥有自己的bable / autoprefixer配置)我已经有babel-core,babel-loader,babel-preset- es2015安装在我自己的package.json中我安装了transform-es2015-modules-strip并再次运行build:

ERROR in ./node_modules/bootstrap/dist/js/bootstrap.js
Module not found: Error: Can't resolve 'jquery' in 'E:\Documente\Work\wordpress\wordpressSite\wp-content\themes\bsTheme\node_modules\bootstrap\dist\js'
 @ ./node_modules/bootstrap/dist/js/bootstrap.js 1:0-17
 @ ./src/app.js

ERROR in ./node_modules/bootstrap/dist/js/bootstrap.js
Module not found: Error: Can't resolve 'popper.js' in 'E:\Documente\Work\wordpress\wordpressSite\wp-content\themes\bsTheme\node_modules\bootstrap\dist\js'
 @ ./node_modules/bootstrap/dist/js/bootstrap.js 1:0-20
 @ ./src/app.js

So I tried and installed jquery and popper in my project as dev dependency...got rid of the jquery error but..: 所以我尝试在我的项目中安装jquery和popper作为dev依赖...摆脱了jquery错误但是......:

ERROR in ./node_modules/bootstrap/dist/js/bootstrap.js
Module not found: Error: Can't resolve 'popper.js' in 'E:\Documente\Work\wordpress\wordpressSite\wp-content\themes\bsTheme\node_modules\bootstrap\dist\js'
 @ ./node_modules/bootstrap/dist/js/bootstrap.js 1:0-20
 @ ./src/app.js

Out of ideas...and this seems over complicated...I can't seem to know what I'm doing wrong, the only thing I can come up with is to get the bootstrap.js file put it directly with my other js files... long post but I wanted to be as specific as possible. 出于想法......这似乎过于复杂......我似乎无法知道我做错了什么,我唯一能想到的就是把bootstrap.js文件直接放到我的其他js文件...很长的帖子但我希望尽可能具体。

What should I do to make it work again, I would really appreciate some help. 我该怎么办才能让它再次发挥作用,我真的很感激一些帮助。 Thank you 谢谢

After several tests this is my conclusion for running bootstrap v4.0.0-beta with Webpack so you will need to manually install jquery and popper.js, it will not be installed by bootstrap as dependencies anymore. 经过多次测试后,这是我使用Webpack运行bootstrap v4.0.0-beta结论,因此您需要手动安装jquery和popper.js,它不会再被bootstrap作为依赖项安装。 It will not work without jquery and the dropdowns/popups will not work without popper.js so: 如果没有jquery,它将无法工作,如果没有popper.js,下拉/弹出窗口将无法工作:

npm install bootstrap@4.0.0-beta -D
npm install jquery -D
npm install popper.js -D

I ended up editing the post, because it was pointed out that popper and popper.js are 2 different libraries(which I didn't knew) I was trying to install popper.js with npm install popper and therefore I had the issue... so installing it with npm install popper.js will install the latest version of it (and the right library). 我最后编辑了帖子,因为有人指出popper和popper.js是2个不同的库(我不知道)我试图用npm install popper安装popper.js因此我有问题..所以用npm install popper.js安装它会安装它的最新版本(和正确的库)。 Then you have to change in the webpack.config.js just as mentioned in https://getbootstrap.com/docs/4.0/getting-started/webpack/ 然后你必须改变webpack.config.js,就像在https://getbootstrap.com/docs/4.0/getting-started/webpack/中提到的那样

plugins: [
    ...
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        Popper: ['popper.js', 'default'],            
        ...
      })
    ...
  ]

Then the rest of the config should be the same as it was for v4 alpha. 然后配置的其余部分应与v4 alpha的相同。 Anyway this is what I found out after struggling with this for a while. 无论如何,这是我在经历了一段时间的努力之后发现的。 Hope it will help someone. 希望它会帮助某人。

I got this error when upgraded to bootstarp latest version 4.0.0 . 升级到bootstarp最新版本4.0.0时出现此错误。

ERROR in ./node_modules/bootstrap/dist/js/bootstrap.js
Module not found: Error: Can't resolve 'popper.js' in 'E:\work\nodejs\mepos\node_modules\bootstrap\dist\js'
 @ ./node_modules/bootstrap/dist/js/bootstrap.js 7:100-120

I just added popper.js dependency and it resolved the issue. 我刚刚添加了popper.js依赖项,它解决了这个问题。 ( jquery was already added in my dependencies) jquery已添加到我的依赖项中)

npm install popper.js --save

I found same error and after some search find design find solution: 我发现相同的错误,经过一些搜索后找到设计找到解决方案

First of all you need install: 首先你需要安装:

npm install babel-plugin-transform-es2015-modules-strip

And them install: 他们安装:

babel-preset-es2015
babel-preset-stage-2

Also i attached to image before and after. 我也在前后附加图像。 Hope is help. 希望是有帮助的。

install the bootstrap without the signal: ^ (npm install bootstrap@^4.0.0-alpha.6) 在没有信号的情况下安装bootstrap:^(npm install bootstrap@^4.0.0-alpha.6)

like this: npm install bootstrap@4.0.0-alpha.6 像这样:npm install bootstrap@4.0.0-alpha.6

It's because of popper, I think? 我认为这是因为波普尔? Popper v1.10 isn't available over npm, so you probably installed Popper v1.0.0 instead. Popper v1.10在npm上不可用,所以你可能已经安装了Popper v1.0.0。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM