Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In vite + vue3 + TS project, AWS Amplify Failed to resolve components

Tags:

I am having hard time to make AWS Amplify work with Vite.js

// First I was getting this error:
Uncaught ReferenceError: global is not defined

So, I added this script in index.html's head section

<script>
  var global = global || window;
  var Buffer = Buffer || [];
  var process = process || {
    env: { DEBUG: undefined },
    version: []
  };
</script>

Now, I am getting this warning/error

[Vue warn]: Failed to resolve component: amplify-sign-out 
[Vue warn]: Failed to resolve component: amplify-authenticator 

You can see complete logs here: enter image description here

like image 924
Syed Avatar asked Apr 01 '21 23:04

Syed


1 Answers

I was able to fix the resolve component errors by creating a vue.config.js file in the app root directory and adding the following:

module.exports = {
  chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .tap(options => {
        options.compilerOptions = {
          ...(options.compilerOptions || {}),
          isCustomElement: tag => tag.startsWith('amplify-')
        };
        return options;
      });
  }
};
like image 74
Luke Halley Avatar answered Sep 21 '22 14:09

Luke Halley