首页 > 解决方案 > Vuejs,Bootstrap-Vue:空白页面:Webpack 说,“无法读取 null 的属性‘绑定’”

问题描述

那里。

我的项目有一个奇怪的故障排除。昨天,它工作正常。渲染的所有页面。在我决定只从 Bootstrap-Vue 导入我正在使用的组件之前没有问题,因为当我从生产环境构建它时,Webpack 说,“项目太重了,性能可能会变慢”。然后所有该死的项目停止工作(如果你去 localhost:8080,你会看到一个空白页面,没有关于正在发生的事情的信息)。我查看了 Bootstrap-Vue 的文档以获取更多信息,并找到了这段代码并粘贴到vue.config.js 中

module.exports = {
configureWebpack: {
  resolve:{
      alias: {
          'bootstrap-vue$' : 'bootstrap-vue/src/index.js'
      }
  },

  module: {
      rules: [
          {
            test: /\.js$/,
            exclude: /node_modules\/(?!bootstrap-vue\/src\/)/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: ['env']
                }
            }
          }
      ],

      resolve: {
        alias: {
          vue$: 'vue/dist/vue.runtime.esm.js',
          vue$: 'vue/dist/vue.esm.js' 
        }
      }
  }
}

}

我再次运行我的项目,这个错误出现了:

Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: /home/juny/AppsWorkspace/twitty-alpha/src/router/index.js: Cannot 
read property 'bindings' of nul

我检查了路由器的“index.js”,没有任何异常。这是'router/index.js'的代码:

import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import About from '../views/About.vue'
import SignUp from '../views/SignUp.vue'
import TwittyUI from '../views/TwittyUI.vue'
import UserProfile from '../views/UserProfile.vue'
import Settings from '../views/Settings.vue'
import Chat from '../views/Chat.vue'
import UserVerified from '../views/userVerified.vue'

Vue.use(VueRouter)

const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: About
},
{
path: '/signUp',
name: 'SignUp',
component: SignUp
},
{
path: '/twit',
name: 'TwittyUI',
component: TwittyUI,
},
{
path: '/userProfile',
name: 'UserProfile',
component: UserProfile,
},
{
path: '/settings',
name: 'Settings',
component: Settings,
},
{
path: '/chat',
name: 'Chat',
component: Chat,
},
{
path: '/userVerified',
name: 'UserVerified',
component: UserVerified,
}
]

const router = new VueRouter({
  routes
}) 

export default router

我的 main.js 文件:

import '@babel/polyfill'
import 'mutationobserver-shim'
import Vue from 'vue'
import './plugins/bootstrap-vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import { 
 BootstrapVue, 
 IconsPlugin,
 LayoutPlugin,
 BForm,
 BFormInput,
 BButton,
 BCard,
 NavbarPlugin,
 FormTagsPlugin
} from 'bootstrap-vue'

Vue.use(BootstrapVue)
Vue.use(IconsPlugin)
Vue.use(LayoutPlugin)
Vue.use(BForm)
Vue.use(BFormInput)
Vue.use(BButton)
Vue.use(BCard)
Vue.use(NavbarPlugin)
Vue.use(FormTagsPlugin)

Vue.config.productionTip = false

new Vue({
 router,
 render: h => h(App)
}).$mount('#app')

..这是我的 package.json 以获得更深入的了解:

 {
   "name": "twitty-alpha",
   "version": "0.1.0",
   "private": true,
   "scripts": {
   "serve": "vue-cli-service serve",
   "build": "vue-cli-service build",
   "test:unit": "vue-cli-service test:unit",
   "test:e2e": "vue-cli-service test:e2e",
   "lint": "vue-cli-service lint"
 },
 "dependencies": {
   "bootstrap-vue": "^2.1.0",
   "core-js": "^3.6.4",
   "firebase": "^7.14.2",
   "idb": "^5.0.2",
   "register-service-worker": "^1.7.1",
   "vue": "^2.6.11",
   "vue-router": "^3.1.6"
 },
 "devDependencies": {
   "@babel/polyfill": "^7.7.0",
   "@vue/cli-plugin-babel": "^4.3.0",
   "@vue/cli-plugin-e2e-cypress": "^4.3.0",
   "@vue/cli-plugin-eslint": "^4.3.0",
   "@vue/cli-plugin-pwa": "^4.3.0",
   "@vue/cli-plugin-router": "^4.3.0",
   "@vue/cli-plugin-unit-jest": "^4.3.0",
   "@vue/cli-service": "^4.3.0",
   "@vue/test-utils": "1.0.0-beta.31",
   "babel-eslint": "^10.1.0",
   "babel-preset-env": "^1.7.0",
   "bootstrap": "^4.3.1",
   "eslint": "^6.7.2",
   "eslint-plugin-vue": "^6.2.2",
   "mutationobserver-shim": "^0.3.3",
   "popper.js": "^1.16.0",
   "portal-vue": "^2.1.6",
   "sass": "^1.19.0",
   "sass-loader": "^8.0.0",
   "vue-cli-plugin-bootstrap-vue": "^0.6.0",
   "vue-template-compiler": "^2.6.11"
  }
}

对不起,对于这篇很长的帖子,但我正试图将所有相关的事情都放在桌面上。所以,其他人可以用它来解决他们的问题。我对 Webpack 和 Babel 没有任何了解,所以我猜这可能是愚蠢的。但这是我不知道的事情。所以,快乐狩猎!让我知道你做了什么。

标签: vue.jswebpackbabeljsbootstrap-vue

解决方案


突然出现的一个问题是您正在使用Vue.use(..)组件和插件......这不起作用。此外Vue.use(BootstrapVue),当您安装所有 BootstrapVue 时(减去图标)。这不是您所期望的。

// Register plugins
Vue.use(IconsPlugin)
Vue.use(LayoutPlugin)
Vue.use(NavbarPlugin)
Vue.use(FormTagsPlugin)
// Register components
Vue.component('BForm', BForm)
Vue.component('BFormInput', BFormInput)
Vue.component('BButton', BButton)
Vue.component('BCard', BCard)

推荐阅读