You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Changes to extension ordering in moduleFileExtensions breaks jest tests #2608
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:
TestsuitefailedtorunJestencounteredanunexpectedtokenThisusuallymeansthatyouaretryingtoimportafilewhichJestcannotparse,e.g.it's not plain JavaScript.
Details:
......./node_modules/graphql/language/parser.mjs:1importinspectfrom'../jsutils/inspect';^^^^^^SyntaxError: Cannotuseimportstatementoutsideamodule
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...
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
Activity
glenveegee commentedon Jul 31, 2020
I should add that there's nothing wrong preferring
mjsoverjsbut 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