amplify-js: Can't import the named export 'Amplify' from non EcmaScript module (only default export is available)
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
16
Amplify CLI Version
11.0.3
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
Following this tutorial - https://amplify.aws/learn/courses/Fullstack-for-Frontend-Developers-e7319/lessons/1
Describe the bug
I’m new to Amplify and am following a tutorial to set up a React app. I’ve deployed using Studio, installed the Amplify CLI, according to the tutorial, but when I use npm run start I keep on getting these errors.
Looking online a lot of places are saying this is a webpack issue, but while webpack is in node_modules, there is no webpack.config file in the project.
Expected behavior
The project should build locally
Reproduction steps
Set up project with data schema etc on Amplify Studio, then:
npx create-react-app notescd notes- CLI previously installed
- `amplify pull’ command as detailed in Studio
npm i aws-amplify @aws-amplify/ui-react- adding
import { Amplify } from 'aws-amplify'; import { AmplifyProvider } from '@aws-amplify/ui-react'; import config from './aws-exports'; Amplify.configure(config)to index.js - Changing the return in App.js to
return ( <></> ) npm run start
Project Identifier
No response
Log output
# Put your logs below this line
Additional information
No response
Before submitting, please confirm:
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- I have removed any sensitive information from my code snippets and submission.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 18 (9 by maintainers)
This issue is happening mainly for older version react-scripts Follow the following troubleshooting guide for resolving this issue
https://ui.docs.amplify.aws/react/getting-started/troubleshooting
for extending CRA config u can use following package https://www.npmjs.com/package/@craco/craco
here is text from given link
Create React App v4 is not officially supported by Amplify UI. When you use it, you may get the following error
./node_modules/@aws-amplify/ui-react/dist/esm/components/..\/\*.mjsCan’t import the named export ‘Amplify’ from non EcmaScript module (only default export is available) To resolve the error, you may either (1) upgrade to Create React App version 5 (Migration Guide), or (2) override the webpack config using tools like React App Rewired, Craco to add the following rule:
Since the issue here seems to be around an older version of
react-scripts, i’ll go ahead and mark this issue as closed.Thanks!
This is the correct solution for me, CRA used version 2.1.3 of react-scripts I changed it to latest version(5.0.1) delete node_modules and rerun npm install and it fixed the issue
Glad it worked @lciano1 😄
@om2345 from your comments, I am assuming that you were able to get things working as well, but let me know if that is incorrect
That fixed it! Thanks!