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

Changes to extension ordering in moduleFileExtensions breaks jest tests #2608

Closed
glenveegee opened this issue Jul 31, 2020 · 1 comment
Closed
Labels

Comments

@glenveegee
Copy link

Stencil version:

I'm submitting a:

[x ] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

I have a stencil component that imports a npm package that has mixed ESM and UMD files in the library. My stencil components builds and runs fine but Jest testing fails because the .mjs file extensions are preferred over the .js file extensions without transforming them. This results in errors like:

Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript. 

    Details:

    ......./node_modules/graphql/language/parser.mjs:1
    import inspect from '../jsutils/inspect';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

Expected behavior:

Jest tests should pass

Steps to reproduce:

Test any component that imports from graphql package or any package that imports from a npm package with mixed ESM and UMD files

Related code:

This started appearing following the commits in
This commit 7 days ago..
781180d

reordered the moduleFileExtensions from

['ts', 'tsx', 'js', 'mjs', 'jsx', 'json', 'd.ts']

to

['ts', 'tsx', 'mjs', 'js', 'jsx']

NOTE mjs now precedes js

Other information:

WORKAROUND

To work around this issue you can override the ordering by setting the moduleFileExtensions in stencil.config.ts to...

testing: {
    ...
    moduleFileExtensions: [
      'ts',
      'tsx',
      'js',
      'mjs',
      'jsx',
      'json',
      'd.ts'
    ]
  },
@ionitron-bot ionitron-bot bot added the triage label Jul 31, 2020
@glenveegee
Copy link
Author

glenveegee commented Jul 31, 2020

I should add that there's nothing wrong preferring mjs over js but then the appropriate and necessary changes also have to be made to jest config such that jest can natively support es modules which it is only now starting to address. See jestjs/jest#9430

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

No branches or pull requests

1 participant