Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing aws-exports.js using typescript generates error. #222

Closed
superandrew opened this issue Feb 2, 2018 · 8 comments
Closed

Importing aws-exports.js using typescript generates error. #222

superandrew opened this issue Feb 2, 2018 · 8 comments
Labels
feature-request Request a new feature
Projects

Comments

@superandrew
Copy link

According to the documentation, I should/could import the aws-exports module after downloading the proper file from mobile HUB, and then use that configuration to initialize Amplify's configuration.

However I am having many troubles doing so. To start, I need to set "allowJs":true in tsconfig.

Then I import everything as specified in docs.

import Amplify from "aws-amplify";
import aws_exports from '../../aws-exports'; 

then use it

ionViewDidLoad() {
    console.log('ionViewDidLoad home');
    Amplify.configure(aws_exports);
  }

But when I do, i get this error: Cannot write file '<path>/aws-exports.js' because it would overwrite input file.
If I dont set allowJS=true I get this error:

 Module '../../aws-exports' was resolved to 
        '<path>/aws-exports.js', but '--allowJs' is not set.

Am I doing something wrong? Is Amplify supposed to be configured in a typescript application, like Ionic application?

Apart from this which I am not sure if it is a bug or improper configuration, any help/link/example would be greatly appreciated.

@superandrew
Copy link
Author

as a reference (I don't know if it is correct or a workaround) I renamed aws-export.js to .ts and compiled it. After that no allowJs was needed.

@mlabieniec
Copy link
Contributor

mlabieniec commented Feb 2, 2018

@superandrew that is exactly what I do for now (rename to .ts for the compiler). We are actively working on a fix for this for TS specifically in the awsmobile-cli, but what you are doing is the correct workaround for now.

@mlabieniec mlabieniec added the feature-request Request a new feature label Feb 2, 2018
@richardzcode
Copy link
Contributor

@superandrew if you don't like to change filename. Use 'require' instead of 'import' works for me. Just be aware when require you get { default } so need to get .default from require.

const aws_exports = require('../../aws-exports').default;

@SagarMhatre
Copy link

Thanks @richardzcode

@mlabieniec mlabieniec added the documentation Related to documentation feature requests label Apr 13, 2018
@mlabieniec mlabieniec added this to Backlog in aws-amplify via automation Apr 13, 2018
@mlabieniec mlabieniec added this to the aws-amplify@0.4 milestone Apr 13, 2018
@mlabieniec
Copy link
Contributor

You can also just rename aws-exports.js to aws-exports.ts and import './aws-exports';

aws-amplify automation moved this from Backlog to @beta Jun 5, 2018
@mbahar mbahar removed the documentation Related to documentation feature requests label Jun 8, 2018
@pbirsinger
Copy link

Still no way to generate aws-exports.ts ? We're nearly late 2019!!

@patfeldman
Copy link

Add new file
aws-exports.d.ts
export = awsmobile; declare const awsmobile: any;

ericclemmons added a commit to ericclemmons/amplify-js that referenced this issue Jan 29, 2021
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request a new feature
Projects
No open projects
aws-amplify
  
@beta
Development

No branches or pull requests

7 participants