Я пытаюсь загрузить сертификат AWS IoT с помощью Vue CLI, но получаю ошибку filesys.existsSync
.
Симптомы похожи на следующие, как это можно устранить?
https://github.com/aws/aws-iot-device-sdk-js/issues/76
Сообщение об ошибке (Home. vue):
vue.esm.js?efeb:1897 TypeError: filesys.existsSync is not a function
at module.exports (tls-reader.js?f650:89)
at new DeviceClient (index.js?71ea:455)
at Object.DeviceClient [as device] (index.js?71ea:216)
at VueComponent.mounted (Home.vue?5584:12)
at invokeWithErrorHandling (vue.esm.js?efeb:1863)
at callHook (vue.esm.js?efeb:4228)
at Object.insert (vue.esm.js?efeb:3148)
at invokeInsertHook (vue.esm.js?efeb:6357)
at Vue.patch [as __patch__] (vue.esm.js?efeb:6576)
at Vue._update (vue.esm.js?efeb:3954)
Полный код источника: https://github.com/yuheijotaki/aws-iot-vue
Основной исходный код:
build / webpack.dev.conf. js
// ...
const fs = require('fs');
const devWebpackConfig = merge(baseWebpackConfig, {
// ...
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/dev.env'),
awsConfig: JSON.stringify({
keyPath: fs.readFileSync(path.resolve(__dirname, '../certs/sample.pem.key')),
certPath: fs.readFileSync(path.resolve(__dirname, '../certs/sample.pem.crt')),
caPath: fs.readFileSync(path.resolve(__dirname, '../certs/root.pem.key')),
debug: true,
clientId: 'nouser' + (Math.floor((Math.random() * 100000) + 1)),
host: 'XXXXXXXXXXXXXXX-ats.iot.ap-northeast-1.amazonaws.com'
})
}),
// ...
index. html
<body>
<script src="/static/js/aws-iot-sdk-browser-bundle.js"></script>
<div id="app"></div>
</body>
src / views /Home.vue
<template>
<div>
<p>index page</p>
</div>
</template>
<script>
var awsIot = require('aws-iot-device-sdk');
export default {
mounted() {
var device = awsIot.device({
keyPath: awsConfig.keyPath,
certPath: awsConfig.certPath,
caPath: awsConfig.caPath,
debug: awsConfig.debug,
clientId: awsConfig.clientId,
host: awsConfig.host
});
device
.on('connect', function() {
console.log('connect');
});
}
}
</script>