14
5

More than 3 years have passed since last update.

AWS Amplifyでnpm run serveした時に、This relative module was not found: ./aws-exports

Last updated at Posted at 2020-02-01

概要

AWS Amplifyで開発したものをGitHub等に格納して、別の作業ディレクトリや別の端末でチェックアウトして作業する際に発生する問題です。
aws-export.jsは.gitignoreに設定されているので、そのままだとファイルが見つからないということになります。

エラー内容

npm run serveすると、下記のようなエラーがコンソールに表示されます。

 ERROR  Failed to compile with 1 errors                                                                      10:22:15 AM

This relative module was not found:

* ./aws-exports in ./src/main.js

対応

How to clone an Amplify project from a git repo and generate aws-exports.js without push (Typescript/javascript/react) · Issue #603 · aws-amplify/amplify-cli
https://github.com/aws-amplify/amplify-cli/issues/603
に書いてありました。

amplify initして、
Do you want to use an existing environment?
にYesで答えるとaws-exports.jsが生成されます。

あと、npm initも忘れずに。

amplify initの実行例

>amplify init
Note: It is recommended to run this command from the root of your app directory
? Do you want to use an existing environment? Yes
? Choose the environment you would like to use: dev
? Choose your default editor: Visual Studio Code
Using default provider  awscloudformation

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html

? Do you want to use an AWS profile? Yes
? Please choose the profile you want to use default
√ Initialized provider successfully.
Initialized your environment successfully.

Your project has been successfully initialized and connected to the cloud!

Some next steps:
"amplify status" will show you what you've added already and if it's locally configured or deployed
"amplify <category> add" will allow you to add features like user login or a backend API
"amplify push" will build all your local backend resources and provision it in the cloud
“amplify console” to open the Amplify Console and view your project status
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud

Pro tip:
Try "amplify add api" to create a backend API and then "amplify publish" to deploy everything


>
14
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
5