TypeError: filesys.existsSync не является функцией

Я пытаюсь загрузить сертификат 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
Основной исходный код:

сборка/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>

источник/представления/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>

person jtk    schedule 09.03.2020    source источник
comment
Я не понимаю, fs.readFileSync должно происходить, когда веб-пакет объединяет ваше приложение, а не при загрузке вашей страницы. Вы уверены, что он жалуется на это конкретное утверждение в вашем файле webpack.dev.conf.js?   -  person Titulum    schedule 09.03.2020
comment
› когда веб-пакет объединяет ваше приложение, а не когда загружается ваша страница. Я не знаю, почему текущий код выдает ошибку.   -  person jtk    schedule 10.03.2020