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

Error on Import when Running CreateReactApp Test #164

Open
yuschick opened this issue Oct 4, 2017 · 3 comments
Open

Error on Import when Running CreateReactApp Test #164

yuschick opened this issue Oct 4, 2017 · 3 comments

Comments

@yuschick
Copy link

yuschick commented Oct 4, 2017

I have included Ally.js into a React/Redux/TypeScript project. Now, that I have made some good progress including it and getting it working I have hit an error when running yarn test before committing the updates. The error is as follows:

FAIL  src/containers/App/tests/index.test.tsx
 ● Test suite failed to run

   [path]/node_modules/ally.js/esm/maintain/disabled.js:21
   import nodeArray from '../util/node-array';
   ^^^^^^

   SyntaxError: Unexpected token import

     at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
     at Object.<anonymous> (src/components/RightSidebar/index.tsx:19:18)
     at Object.<anonymous> (src/components/Layout/index.tsx:6:22)

I have imported the components in from the ESM directory and added them to my types file for ActionScript.

declare module 'ally.js/esm/maintain/disabled';
declare module 'ally.js/esm/maintain/tab-focus';
declare module 'ally.js/esm/query/first-tabbable';
declare module 'ally.js/esm/when/key';

And inside my RightSidebar component I bring the components in with the following:

import AllyDisabled from 'ally.js/esm/maintain/disabled';
import AllyTabFocus from 'ally.js/esm/maintain/tab-focus';
import AllyKey from 'ally.js/esm/when/key';

Running this works fine as I've gotten the functionality to work. Only now when I run yarn test do I hit the error.

@rodneyrehm
Copy link
Member

Is it possible that the test runner (whichever that is?!) is not capable of handling ES6 Modules?

@yuschick
Copy link
Author

yuschick commented Oct 9, 2017

I am using CreateReactApp which by default supports Jest. Since CRA does support ES6 syntax, I am unsure if that is the issue here. I would also suspect it would occur in more files than just nodeArray.

I've tried a couple different workarounds but with no luck yet.

@yuschick
Copy link
Author

yuschick commented Nov 7, 2017

I was able to solve this issue by the following:

  • I installed the 'babel-polyfill' package
  • Included `import 'babel-polyfill' at the top of my entry point file for my app

I will have a blog up this week going over this process and working with Ally.js within React and Typescript.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants