Encountering an issue with cypress.
Within my repository, I have 3 workspaces: backend, common, and frontend.
package/
backend/
jest.config.cjs
tsconfig.json
utils/
common/
jest.config.cjs
tsconfig.json
utils/
helpers/
frontend/
cypress.config.ts
tsconfig.json
utils/
While working in the common workspace, I have implemented absolute paths.
- Backend
package.json
"dependencies": {
"@package-common": "workspace:^",
}
jest.config.cjs
module.exports = {
...
moduleNameMapper: {
'@utilsCommon/(.*)$': '@package-common/utils/$1',
},
};
- Common
jest.config.cjs
module.exports = {
...
moduleNameMapper: {
'@utilsCommon/(.*)$': '<rootDir>/utils/$1',
},
};
tsconfig.json
{
...
"compilerOptions": {
...
"baseUrl": "./",
"paths": {
"@utilsCommon/*": ["utils/*"]
}
},
}
- Frontend
package.json
"dependencies": {
"@package-common": "workspace:^",
}
cypress.config.ts
on(
'file:preprocessor',
webpack({
webpackOptions: {
resolve: {
...
alias: {
'@utilsCommon': resolve(__dirname, '../common/utils'),
},
},
When running tests with Cypress or Jest, the functions imported via alias in the common package are not found.
./common/utils/services/http.service.ts
import {
getUrlApiFhirStaging,
} from '@utilsCommon/helpers';
view image description here view image description here
Attempts to adjust the cypress.config.ts file have been unsuccessful.
cypress.config.ts
on(
'file:preprocessor',
webpack({
webpackOptions: {
resolve: {
...
alias: {
'@utilsCommon': resolve('@package-common/utils'),
},
},