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

Typescript support: Electron is reading the wrong tsconfig.json #7043

Closed
tspmelo opened this issue Apr 16, 2020 · 5 comments · Fixed by #7197
Closed

Typescript support: Electron is reading the wrong tsconfig.json #7043

tspmelo opened this issue Apr 16, 2020 · 5 comments · Fixed by #7197
Labels
topic: typescript type: regression A bug that didn't appear until a specific Cy version release v4.4.0 🐛 Issue present since 4.4.0

Comments

@tspmelo
Copy link

tspmelo commented Apr 16, 2020

Current behavior:

In 4.4.0, using the included TypeScript support I cannot run tests in Electron.
Using Chrome still works.

The problem I'm facing seems to be related to the tsconfig.json file I have at the root of my project.
If that file is removed, Electron starts working again.

When I try to run with Electron I'm getting this:

npm run cypress:run

...

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    4.4.0                                                                              │
  │ Browser:    Electron 80 (headless)                                                             │
  │ Specs:      1 found (spec.ts)                                                                  │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  spec.ts                                                                         (1 of 1)
Cannot use import statement outside a module
/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/lib/browsers/electron.js:1
import * as tslib_1 from "tslib";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:896:18)
    at Module.m._compile (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/ts-node/src/index.ts:536:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:986:10)
    at Object.require.extensions.<computed> [as .js] (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/ts-node/src/index.ts:539:12)
    at Module.load (internal/modules/cjs/loader.js:816:32)
    at Module._load (internal/modules/cjs/loader.js:728:14)
    at Module._load (electron/js2c/asar.js:717:26)
    at Function.Module._load (electron/js2c/asar.js:717:26)
    at Module.require (internal/modules/cjs/loader.js:853:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at getBrowserLauncher (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/lib/browsers/index.js:51:12)
    at /home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/lib/browsers/index.js:189:31
    at tryCatcher (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromiseCtx (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:641:10)
    at _drainQueueStep (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:97:12)
    at _drainQueue (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/tspmelo/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

Desired behavior:

  • It should work in all browsers.
  • Electron should not read tsconfig.json
  • Both browsers were working in 4.3.0, using webpack preprocessor.

Test code to reproduce

Before knowing about cypress-test-tiny I created a reproducible example in cypress-example-recipes: tspmelo/cypress-example-recipes@4a310b1
If needed I can move the code to the other repo.
(And if you think it would be a good addition, I can open a working PR in cypress-example-recipes with the example used here)

cd examples/preprocessors__typescript-none
npm run cypress:run  # Will fail
npm run cypress:run -- --browser chrome # Will work

rm tsconfig.json
npm run cypress:run  # Will work

Versions

OS: Linux
Cypress 4.4.0
Browsers:
- Electron: 80
- Chrome: 80
@jennifer-shehane jennifer-shehane added topic: typescript v4.4.0 🐛 Issue present since 4.4.0 labels Apr 17, 2020
@jennifer-shehane
Copy link
Member

I can recreate this. Have a cypress project with typescript installed in Cypress 4.4.0 and add the following tsconfig.json to the root of the project then run cypress run.

{
  "compilerOptions": {
    "importHelpers": true,
    "module": "esnext",
    "target": "es2015",
    "allowJs": true
  }
}

Fails only in Electron with following stacktrace

 cypress run

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    4.4.0                                                                              │
  │ Browser:    Electron 80 (headless)                                                             │
  │ Specs:      1 found (spec.js)                                                                  │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  spec.js                                                                         (1 of 1)
Cannot use import statement outside a module
/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/browsers/electron.js:1
import { __awaiter } from "tslib";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:896:18)
    at Module.m._compile (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/ts-node/src/index.ts:536:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:986:10)
    at Object.require.extensions.<computed> [as .js] (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/ts-node/src/index.ts:539:12)
    at Module.load (internal/modules/cjs/loader.js:816:32)
    at Module._load (internal/modules/cjs/loader.js:728:14)
    at Module._load (electron/js2c/asar.js:717:26)
    at Function.Module._load (electron/js2c/asar.js:717:26)
    at Module.require (internal/modules/cjs/loader.js:853:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at getBrowserLauncher (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/browsers/index.js:51:12)
    at /Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/browsers/index.js:189:31
    at tryCatcher (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromiseCtx (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:641:10)
    at _drainQueueStep (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:97:12)
    at _drainQueue (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/jennifer/Library/Caches/Cypress/4.4.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

@cypress-bot cypress-bot bot added the stage: needs investigating Someone from Cypress needs to look at this label Apr 17, 2020
@jennifer-shehane jennifer-shehane added type: regression A bug that didn't appear until a specific Cy version release and removed type: bug labels Apr 28, 2020
@izayl
Copy link

izayl commented Apr 29, 2020

@jennifer-shehane any progress here? Cypress 4.5.0 have the same issue.

@zetoke
Copy link

zetoke commented Apr 29, 2020

@izayl +1
And It's not only Electron related.
People in other set ups are also having the same problems with importing helpers #7011 (comment)

@cypress-bot cypress-bot bot added stage: work in progress stage: ready for work The issue is reproducible and in scope stage: needs review The PR code is done & tested, needs review and removed stage: needs investigating Someone from Cypress needs to look at this stage: work in progress stage: ready for work The issue is reproducible and in scope stage: needs review The PR code is done & tested, needs review labels May 1, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels May 4, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 4, 2020

The code for this is done in cypress-io/cypress#7197, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 20, 2020

Released in 4.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.6.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: typescript type: regression A bug that didn't appear until a specific Cy version release v4.4.0 🐛 Issue present since 4.4.0
Projects
None yet
4 participants