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-amplify-react', ERROR: Uncaught SyntaxError: Unexpected token : #2230

Closed
robbylucia opened this issue Dec 2, 2018 · 15 comments · Fixed by #5138
Closed

importing 'aws-amplify-react', ERROR: Uncaught SyntaxError: Unexpected token : #2230

robbylucia opened this issue Dec 2, 2018 · 15 comments · Fixed by #5138
Assignees
Labels
feature-request Request a new feature React React related issues

Comments

@robbylucia
Copy link

Describe the bug
Trying to import aws-amplify-react into an electron-react-boilerplate component yields the following error in the electron browser:
vm.js:74 Uncaught SyntaxError: Unexpected token : at new Script (vm.js:74) at createScript (vm.js:246) at Object.runInThisContext (vm.js:298) at Module._compile (internal/modules/cjs/loader.js:678) at Object.Module._extensions..js (internal/modules/cjs/loader.js:722) at Module.load (internal/modules/cjs/loader.js:620) at tryModuleLoad (internal/modules/cjs/loader.js:559) at Function.Module._load (internal/modules/cjs/loader.js:551) at Module.require (internal/modules/cjs/loader.js:658) at require (internal/modules/cjs/helpers.js:20)

To Reproduce
Steps to reproduce the behavior:

  1. Install electron-react-boilerplate
  2. Import 'aws-amplify-react' in a component.
  3. yarn dev
  4. Electron app starts but page breaks. Blank page and browser error.

Expected behavior
Have module be imported and have my component/react app working and displaying.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Electron (Chrome)

Additional context
A maintainer of electron-react-boilerplate said it may be related to requiring CSS or something. Not sure.
electron-react-boilerplate/electron-react-boilerplate#2040 (comment)

Does anyone have an idea?

@manueliglesias manueliglesias added investigating This issue is being investigated React React related issues labels Dec 2, 2018
@barrypeterson
Copy link

Having this same issue with the electron-react-boilerplate and amplify. After taking a quick look, @aws-amplify/ui/dist/style.css is actually postcss, not css. This is then required by aws-amplify-react/dist/Amplify-UI/Amplify-UI-Components-React.js

@jordanranz
Copy link
Contributor

Hi @robbylucia,

We may need to bundle our css in the react package with something like rollup for it to properly work with that electron boilerplate package. I will look into what is required for this.

As a workaround you should be able to spin up a create-react-app and then add electron to it. Here is an example article tutorial:
https://medium.freecodecamp.org/building-an-electron-application-with-create-react-app-97945861647c

@barrypeterson The files in src/ are indeed PostCSS but the listed file @aws-amplify/ui/dist/style.css is still a plain css as it has been compiled using webpack.

@cgarvis
Copy link

cgarvis commented Dec 18, 2018

I found a workaround here: vercel/next-plugins#267 (comment)

@robbylucia
Copy link
Author

Hey @cgarvis , thanks for that, although I'm having trouble figuring out where to put this fix for a production build of electron. It only fixes the problem in dev when I place it at the top of babel.config.js, prod is still an issue for me. Any ideas?

@robbylucia
Copy link
Author

As a workaround you should be able to spin up a create-react-app and then add electron to it. Here is an example article tutorial:
https://medium.freecodecamp.org/building-an-electron-application-with-create-react-app-97945861647c

Hey @jordanranz ,
thanks for the suggestion, but I've already rebuilt my project a few times while encountering issues, so I'm averse to starting over again. Is there another workaround? I have everything in my project ready to go, it's just I can't utilize Amplify if I can't import it, and I'd hate to have to switch to something else so far along in my project.

@jordanranz
Copy link
Contributor

hey @robbylucia,

Wouldn't want you to have to start over.

The main problem is that the build process is not recognizing/loading .css files. Here is an alternative work around: If you are using that electron boilerplate, you should be able to add a css loader to the webpack configuration: https://github.com/webpack-contrib/css-loader.

We need to add a similar process to our react package for this to be a permanent fix. This requires us to have a bundler. I have started to test out a few bundlers for this. This is a high priority item that should be fixed within the next month. I will update this as soon as this change has been made.

@jordanranz jordanranz added this to the Triage milestone Feb 5, 2019
@JoWolp
Copy link

JoWolp commented Feb 19, 2019

Hi @jordanranz,
Thank for working on this issue.
I am currently using the same setup as @robbylucia described with the react-electron-boilerplate, but I'm stuck at the error issued here.

Can you or someone else maybe elaborate more on the css loader workaround you mentioned?

@patotoma
Copy link

I stumbled upon this issue myself, workaround for me was to use UMD build instead.

@sammartinez sammartinez added feature-request Request a new feature and removed enhancement labels Jun 17, 2019
@aldegoeij
Copy link

@patotoma sorry, could you elaborate on what the UMD build is and where to get it?
I have the same issue using gatsby, including Amplify breaks the build...

@aldegoeij
Copy link

aldegoeij commented Jul 4, 2019

@sammartinez @jordanranz what would be the current workaround for this issue? I'm having similar problems using plain import Amplify from ""aws-amplify" using Gatsby: dabit3/gatsby-auth-starter-aws-amplify#21

@patotoma
Copy link

patotoma commented Jul 4, 2019

You can get UMD build using CDN e.g. https://unpkg.com/aws-amplify@1.1.7/dist/aws-amplify.min.js

You will then use it in a script tag like this:

<script src="https://unpkg.com/aws-amplify@1.1.7/dist/aws-amplify.min.js" crossorigin="anonymous"></script>

@kkumar4
Copy link

kkumar4 commented Jul 11, 2019

any update on this issue ?

@xpopov
Copy link

xpopov commented Aug 5, 2019

The issue with electron-react-boilerplate is still there. It seems that aws-amplify-react uses basic TS:
"build": "npm run clean && tsc -p .", and when it imports CSS file, it transpiles to require(). Webpack configuration for electron-react-boilerplate does not support this, and css in the /dist seems to be in the same format as in the /src.

I've found workaround for this (not sure if it works in production).
I've moved aws-amplify-react to devDependencies, it removed the original error, but now aws-amplify is missing CSS styles.

Then I've just added @import '~@aws-amplify/ui/dist/style.css'; to app.global.css, and CSS was added into the project.

Probably the fix could be using proper CSS transpiler.

@sammartinez
Copy link
Contributor

This was resolved back in March. Please let us know if you are still having issues.

@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 25, 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 React React related issues
Projects
None yet