question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript aliases not recognized when tsconfig.json file is in Cypress folder

See original GitHub issue

Current behavior

When trying to import an Enum alias from a Typescript file within the Cypress folder as described in the docs, the webpack cannot resolve the alias, even though it is defined in the tsconfig.json file

Desired behavior

Properly import aliases from tsconfig.json files in the Cypress folder without needing to place tsconfig.json with at root project directory.

Test code to reproduce

https://github.com/shawn-e-harris/typeScriptAlias.git

Cypress Version

8.2.0

Other

Error: Webpack Compilation Error
./cypress/support/helper/helpers.js
Module not found: Error: Can't resolve '@alias-example/sub-folder/app-code.ts' in '/Users/joel.whalen/Documents/src/reproducers/alias-error-cypress/cypress/support/helper'
resolve '@alias-example/sub-folder/app-code.ts' in '/Users/joel.whalen/Documents/src/reproducers/alias-error-cypress/cypress/support/helper'
  Parsed request is a module
  using description file: /Users/joel.whalen/Documents/src/reproducers/alias-error-cypress/package.json (relative path: ./cypress/support/helper)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
TomaszGcommented, Nov 8, 2021

@jennifer-shehane I see you’ve added the existing workaround label, could you point to that workaround?

3reactions
DevKhairacommented, Jul 8, 2022

Is there a solution when there is a tsconfig that exists outside the cypress folder (in root), I want to create a few component tests, but blocked by this issue. I have tried to use the ts-loader, but to no avail

the folder stricture is root cypress/ -all the cypress goodies including a tsconfig file that extends the root tsconfig file -tsconfig.json (where the paths exist)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using TypeScript aliases in Cypress tests - Gleb Bahmutov
We can rename our test file from spec.js to spec.ts - and it should run the same. Since the tsconfig.json file is only...
Read more >
Specify tsconfig.json location for Cypress - Stack Overflow
It is build with create-react-app and TypeScript. The tsconfig.json used for Cypress is located in the cypress directory. It is possible you ...
Read more >
TypeScript - Cypress Documentation
Configure tsconfig.json · Open the command palette (Mac: cmd+shift+p , Windows: ctrl+shift+p ) · Type "restart ts" and select the "TypeScript: Restart TS...
Read more >
API - ESBuild
The build API call operates on one or more files in the file system. ... an alias, the resulting import path is resolved...
Read more >
Typescript does not resolve modules through tsconfig.json's ...
The problem is that you have "files":[] section that only includes a file from typings. If there is a 'files' section in tsconfig.json,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found