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

moduleNameMapper override for tslib is causing error when using esm #974

Closed
viceice opened this issue Jul 27, 2021 · 2 comments · Fixed by #976
Closed

moduleNameMapper override for tslib is causing error when using esm #974

viceice opened this issue Jul 27, 2021 · 2 comments · Fixed by #976
Labels
🐛 Bug Confirmed Bug is confirmed

Comments

@viceice
Copy link

viceice commented Jul 27, 2021

🐛 Bug Report

I'm using an angular nx workspace with jest projects. I need to use esm because i've some web worker usages.

See error below. My workaround is to set allowJs=true to my tsconfig.spec.json so tslib will be compiled by this project.

To Reproduce

Steps to reproduce the behavior:

Create a nx workspoace with angular preset and some dummy libs.
Configure for esm and run tests.

Expected behavior

Simply run tests without explicit workaround.

Link to repo (highly encouraged)

I can provide a sample maybe later.

Error log:

# content of error stacktrace :
C:\Users\kriese\projects\visualon\xfab\sx\node_modules\tslib\tslib.es6.js:24
    export function __extends(d, b) {
    ^^^^^^

    SyntaxError: Unexpected token 'export'

      at Runtime.createScriptFromCode (../../node_modules/jest-runtime/build/index.js:1479:14)

envinfo

System: 
    OS: Windows 10 21H1

Npm packages:
    jest: 27.0.6
    jest-preset-angular: 9.0.5
    typescript: 4.3.5
    tslib: 2.3.0
@viceice viceice added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jul 27, 2021
@viceice
Copy link
Author

viceice commented Jul 27, 2021

I think it's because of this line

tslib: 'tslib/tslib.es6.js',

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 31, 2021

We have 2 choices here: either always set allowJs: true internally or remove the mapping of tslib. I prefer the 1st choice as mapping tslib is required if running Jest in ESM mode.

@ahnpnl ahnpnl added 🐛 Bug Confirmed Bug is confirmed and removed Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jul 31, 2021
ahnpnl added a commit that referenced this issue Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Confirmed Bug is confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants