首页 新闻 会员 周边 捐助

webpack打包报错Cannot read property 'bindings' of null

0
[已关闭问题] 关闭于 2018-12-09 21:39

这几天学vue,接触了一下webpack
运行打包的时候提示错误Cannot read property 'bindings' of null
但是将入口文件中的一段JS注释掉就不报错了,注释的内容是
const root = document.createElement("div")
document.body.appendChild(root)
如果把const改成var就没错了
但虽然打包不报错,运行网页提示Cannot read property 'appendChild' of null
我怀疑是babel-loader的版本兼容性问题,导致不能解析es6的语法
webpack.config.js中babel-loader的设置
{
test: /.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
['env', {
targets: {
browsers: ['> 1%', 'last 2 versions']
}
}]
]
}
},
exclude: path.join(__dirname, 'node_modules'),
include: path.join(__dirname, 'src')
}
package.json中babel,vue和webpack的版本
"devDependencies": {
"@babel/core": "^7.0.0",
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.4",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^1.0.1",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"less": "^3.9.0",
"less-loader": "^4.1.0",
"style-loader": "^0.23.1",
"vue-template-compiler": "^2.5.17",
"webpack": "^4.26.1",
"webpack-cli": "^3.1.2"
},
"dependencies": {
"ajv": "^6.0.0",
"requirejs": "^2.3.6",
"save-dev": "^2.0.0",
"vue": "^2.5.17",
"vue-loader": "^14.2.2"
}
请问应该怎么解决呢
本人完全是小白,刚学了两天

入口文件的全部代码是
import Vue from 'vue'
import App from '../vue/app.vue'

var root = document.createElement("div")
document.body.appendChild(root)

new Vue({
render:(h)=>h(App)
}).$mount(root);

teagueli的主页 teagueli | 初学一级 | 园豆:75
提问于:2018-11-30 17:28
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册