尝试运行应用程序时在控制台中收到此错误代码。
webcomponents-lite.js:64Uncaught TypeError: Cannot read property 'getAttribute' of null
at webcomponents-lite.js:64
at Object.549 (webcomponents-lite.js:74)
at __webpack_require__ (bootstrap a218042…:52)
at Object.1242 (webcomponents.bundle.js:8)
at __webpack_require__ (bootstrap a218042…:52)
at webpackJsonpCallback (bootstrap a218042…:23)
at webcomponents.bundle.js:2
这就是我使用 webpack 实例化脚本的方式:
entry: {
'polyfills': './src/polyfills.browser.ts',
'vendor': './src/vendor.browser.ts',
'main': './src/main.browser.ts',
'webcomponents': './bower_components/webcomponentsjs/webcomponents-lite.js',
},
我在使用 webpack 条目对象时收到此错误,但如果我改为使用:
<script src="/webcomponentsjs/webcomponents-lite.js"></script>
在我的index.html页面上它可以正常工作,没有错误。
有人有这方面的经验吗?
编辑::::
<小时/>我和我的同事有相同版本的 Bower_Components 和 Node_Components,删除并重新安装了所有内容。他的作品和我的作品没有。当我们查看 Bower_components 文件时,我们注意到我们有不同的文件和文件夹(不知道如何)。将他们项目中的 Bower_components 文件发送给我并将我的 Bower 文件替换为他们的文件后,它起作用了......
最佳答案
您似乎没有使用正确版本的 webcomponents-lite.js
。正如 @Bobort 所建议的,当前分支不起作用。删除已安装的版本,然后安装 last release .
您还可以使用 Bower 来获取它:
> bower i -S webcomponentsjs
也许您在标签中导入的版本与您在 Webpack 中使用的版本不同。
关于javascript - webcomponents-lite.js 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41600649/