This repo reproduces an error that occurs in a CRA + TypeScript + Cypress app,
when a Cypress test tries to import a file from the src
directory.
npm run cypress
this-fails.js
, this-succeeds.js
The test in cypress/integration/this-fails.js tries to import a constant in src/constants.ts. The test fails with the following error:
./src/constants.ts
Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for /my-app/src/constants.ts.
@ ./cypress/integration/with-import-from-src.spec.js 1:0-50 6:10-21
@ multi ./cypress/integration/with-import-from-src.spec.js
/my-app/src/App.test.tsx
[tsl] ERROR in /my-app/src/App.test.tsx(5,1)
TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
/my-app/src/App.test.tsx
[tsl] ERROR in /my-app/src/App.test.tsx(8,3)
TS2304: Cannot find name 'expect'.
These were the steps taken to create this codebase.
Install CRA with TypeScript
yarn create react-app my-app --template typescript
cd ./my-app
Install Cypress
yarn add cypress --dev
Install Cypress TypeScript support
yarn add @bahmutov/add-typescript-to-cypress --dev
Make changes found in the following files:
baseUrl
)exclude
and compilerOptions
)