Description
Self-service
- I'd be willing to implement a fix
Describe the bug
The company I work for has a Yarn-managed Nx Monorepo comprising mostly of TypeScript apps. We are using Yarn 1.22.19 for this Monorepo, so forgive me if this was an issue that was fixed in versions 2+.
Whenever I run commands like 'yarn install' or 'yarn add', it breaks the typescript path aliases I have for local, proprietary libraries that these apps use and I receive this error:
Error: Cannot find module '@my-services/mylib'
Require stack:
...
Whenever I build an app and examine the compiled main.js file in the dist folder, I noticed that the path aliases do not compile to their actual location, they remain '@my-services/mylib', for example
I have, however, found a quick and dirty fix for this, and that is to rename all of the path aliases. So if I rename them to, say '@this-services/mylib' they build and compile correctly.
The Nx Monorepo has one package.json for the whole monorepo that sits in the root directory. This is an example of how a local library is listed as a dependency in the package.json:
"@my-services/mylib": "file:libs/mylib",
This is an example of how a local library is listed in the yarn.lock:
"@my-services/mylib@file:libs/mylib":
version "0.0.0"
To further confirm that it may be Yarn, I have tested it with this flow:
- yarn install
- build
- compile
- ERROR
- rename
- yarn install
- build
- compile
- SAME ERROR
Please let me know what other information I need to provide, I will try my best to provide it.
To reproduce
{
"name": "my-services",
"version": "0.0.0",
"license": "MIT",
"scripts": {
// scripts
},
"private": true,
"dependencies": {
"@google-cloud/local-auth": "2.1.0",
"@lingui/react": "4.0.0-next.8",
"@mui/icons-material": "^5.11.9",
"@mui/lab": "^5.0.0-alpha.120",
"@mui/material": "^5.11.9",
"@mui/styled-engine-sc": "^5.11.9",
"@mui/x-data-grid": "^5.17.24",
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/sequelize": "^9.0.0",
"@nrwl/next": "15.0.13",
"@slack/web-api": "^6.8.0",
"@my-services/mylib": "file:libs/mylib",
"@supercharge/promise-pool": "^2.3.2",
"@whitebox-co/walmart-marketplace-api": "^3.0.1",
"amqplib": "^0.10.3",
"axios": "^0.27.2",
"class-sanitizer": "^1.0.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"core-js": "^3.6.5",
"csv-parser": "^3.0.0",
"dotenv": "^16.0.1",
"ebay-api": "^8.4.0",
"excel4node": "^1.8.0",
"exceljs": "^4.3.0",
"expression-match": "^0.0.17",
"fastest-levenshtein": "^1.0.16",
"file-system-cache": "^2.0.2",
"formik": "^2.2.9",
"ftp": "^0.3.10",
"fuzzy-matching": "^0.4.3",
"googleapis": "^110.0.0",
"humanize-duration": "^3.27.3",
"limiter": "^2.1.0",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"mssql": "^9.0.0",
"next": "13.1.6",
"node-cron": "^3.0.2",
"pg": "^8.8.0",
"promise-retry": "^2.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-is": "18.2.0",
"react-pro-sidebar": "^1.0.0",
"reflect-metadata": "^0.1.13",
"regenerator-runtime": "0.13.7",
"rxjs": "^7.0.0",
"sequelize": "^6.21.6",
"sequelize-auto": "^0.8.8",
"sequelize-cli-multi-db": "^6.6.0",
"sequelize-typescript": "^2.1.3",
"styled-components": "5.3.5",
"tedious": "^15.1.1",
"tmp": "^0.2.1",
"tslib": "^2.6.1",
"unzipper": "^0.10.11",
"uuidv4": "^6.2.13",
"winston": "^3.8.2",
"yup": "^1.0.0"
},
"devDependencies": {
"@angular-devkit/core": "14.2.10",
"@lingui/cli": "4.0.0-next.8",
"@lingui/loader": "4.0.0-next.8",
"@lingui/macro": "4.0.0-next.8",
"@lingui/swc-plugin": "4.0.0-next.3",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@nrwl/cli": "15.0.13",
"@nrwl/cypress": "15.0.13",
"@nrwl/eslint-plugin-nx": "15.0.13",
"@nrwl/jest": "15.0.13",
"@nrwl/js": "15.0.13",
"@nrwl/linter": "15.0.13",
"@nrwl/nest": "15.0.13",
"@nrwl/node": "15.0.13",
"@nrwl/react": "15.0.13",
"@nrwl/web": "15.0.13",
"@nrwl/workspace": "15.0.13",
"@testing-library/react": "13.4.0",
"@types/jest": "28.1.1",
"@types/node": "18.7.18",
"@types/react": "18.0.20",
"@types/react-dom": "18.0.6",
"@types/react-is": "17.0.3",
"@types/sequelize": "^4.28.14",
"@types/styled-components": "5.1.26",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"babel-jest": "28.1.1",
"babel-plugin-styled-components": "1.10.7",
"cypress": "^10.7.0",
"eslint": "~8.15.0",
"eslint-config-next": "13.1.6",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsx-a11y": "6.6.1",
"eslint-plugin-react": "7.31.8",
"eslint-plugin-react-hooks": "4.6.0",
"jest": "28.1.1",
"jest-environment-jsdom": "28.1.1",
"nx": "15.0.13",
"nx-cloud": "^16.0.5",
"prettier": "^2.6.2",
"react-test-renderer": "18.2.0",
"sequelize-typescript-generator": "^8.4.4",
"sqlite3": "^5.0.11",
"ts-jest": "28.0.5",
"ts-node": "10.9.1",
"typescript": "~4.7.2"
}
}
Environment
System:
- OS: macOS Monterey version 12.5
- CPU: 3.2 GHz Quad-Core Intel Core i5
- Node: 16.19.1
- Yarn: 1.22.19
- npm: 8.19.3
Additional context
Here is the tsconfig.base.json that sits in the root directory:
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": ".",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"module": "esnext",
"lib": ["es2017", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"@my-services/mylib": ["libs/mylib/src/index.ts"],
// other libs
}
},
"exclude": ["node_modules", "tmp"]
}