依赖关系在错误的地方与纱线
Posted
技术标签:
【中文标题】依赖关系在错误的地方与纱线【英文标题】:dependencies in the wrong place with yarn 【发布时间】:2021-12-22 09:19:41 【问题描述】:当我在我的 Typescript 项目(下面的各种 package.json
文件)中执行 yarn install && yarn workspace frontend install && yarn workspace backend install
时,(例如)Angular 和 CDK 的依赖项都在根 node_modules
文件夹中,但是当我运行(例如)yarn workspace frontend ng build
,我得到An unhandled exception occurred: ENOENT: no such file or directory, lstat '/work/frontend/node_modules/@angular'
。如何在正确的位置获取依赖项?
根package.json
:
"name": "load-tester",
"version": "1.0.0",
"private": true,
"workspaces": [
"backend",
"frontend"
],
"scripts":
"deploy": "yarn workspace frontend ng build && yarn workspace backend deploy"
,
"packageManager": "yarn@3.1.0",
"dependencies":
"@aws-sdk/client-ec2": "^3.34.0",
"@aws-sdk/client-elastic-load-balancing-v2": "^3.34.0",
"@middy/http-content-negotiation": "^2.5.1",
"esbuild": "^0.12.28"
frontend/package.json
"name": "frontend",
"version": "0.0.0",
"scripts":
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
,
"private": true,
"dependencies":
"@angular/animations": "~12.2.0",
"@angular/cdk": "12.2.6",
"@angular/common": "~12.2.0",
"@angular/compiler": "~12.2.0",
"@angular/core": "~12.2.0",
"@angular/forms": "~12.2.0",
"@angular/material": "~12.2.6",
"@angular/platform-browser": "~12.2.0",
"@angular/platform-browser-dynamic": "~12.2.0",
"@angular/router": "~12.2.0",
"@aws-sdk/client-sns": "^3.34.0",
"@okta/okta-angular": "^4.1.0",
"@okta/okta-auth-js": "^5.6.0",
"rxjs": "~6.6.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
,
"devDependencies":
"@angular-devkit/build-angular": "~12.2.5",
"@angular/cli": "~12.2.5",
"@angular/compiler-cli": "~12.2.0",
"@angular/localize": "^12.2.5",
"@types/jasmine": "~3.8.0",
"@types/node": "^12.11.1",
"jasmine-core": "~3.8.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~4.3.5"
backend/package.json
"name": "backend",
"scripts":
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk",
"deploy": "yarn build && yarn cdk deploy"
,
"devDependencies":
"@aws-cdk/assert": "^1.121.0",
"@aws-cdk/aws-apigateway": "1.121.0",
"@aws-cdk/aws-apigatewayv2": "1.121.0",
"@aws-cdk/aws-apigatewayv2-integrations": "1.121.0",
"@aws-cdk/aws-certificatemanager": "1.121.0",
"@aws-cdk/aws-dynamodb": "1.121.0",
"@aws-cdk/aws-ecs": "^1.121.0",
"@aws-cdk/aws-ecs-patterns": "^1.121.0",
"@aws-cdk/aws-lambda": "1.121.0",
"@aws-cdk/aws-lambda-event-sources": "1.121.0",
"@aws-cdk/aws-lambda-nodejs": "1.121.0",
"@aws-cdk/aws-logs": "1.121.0",
"@aws-cdk/aws-s3-deployment": "1.121.0",
"@aws-cdk/aws-sqs": "^1.121.0",
"@aws-solutions-constructs/aws-cloudfront-s3": "1.121.0",
"@types/aws-lambda": "^8.10.83",
"@types/http-errors": "^1.8.1",
"@types/jest": "^27.0.1",
"@types/node": "^16.9.6",
"@types/source-map-support": "^0.5.4",
"aws-cdk": "^1.121.0",
"eslint": "^7.32.0",
"jest": "^27.2.0",
"json-schema-to-ts": "^1.6.4",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
,
"dependencies":
"@aws-cdk/aws-apigatewayv2-authorizers": "^1.130.0",
"@aws-cdk/cloud-assembly-schema": "^1.121.0",
"@aws-cdk/core": "^1.121.0",
"@aws-cdk/cx-api": "^1.121.0",
"@aws-cdk/region-info": "^1.121.0",
"@aws-sdk/client-dynamodb": "^3.34.0",
"@aws-sdk/client-ecs": "^3.34.0",
"@aws-sdk/client-elastic-load-balancing-v2": "^3.34.0",
"@aws-sdk/client-route-53": "^3.34.0",
"@aws-sdk/client-s3": "^3.34.0",
"@aws-sdk/client-sqs": "^3.34.0",
"@aws-sdk/lib-dynamodb": "^3.34.0",
"@aws-sdk/signature-v4-crt": "^3.34.0",
"@dazn/lambda-powertools-logger": "^1.28.1",
"@dazn/lambda-powertools-pattern-basic": "^1.29.0",
"@middy/core": "^2.5.1",
"@middy/http-cors": "^2.5.1",
"@middy/http-error-handler": "^2.5.1",
"@middy/http-json-body-parser": "^2.5.1",
"@middy/http-multipart-body-parser": "^2.5.1",
"@middy/sqs-json-body-parser": "^2.5.1",
"@middy/validator": "^2.5.1",
"@okta/jwt-verifier": "^2.3.0",
"ajv": "^8.6.3",
"aws-lambda": "^1.0.6",
"constructs": "^3.2.0",
"exponential-backoff": "^3.1.0",
"http-errors": "^1.8.0",
"middy-jsonapi": "2.0.1",
"source-map-support": "^0.5.16"
【问题讨论】:
【参考方案1】:问题原来是我的angular.json
;特别是在任何地方引用./node_modules/@angular
。当我将其更改为 ../node_modules/@angular
时,我能够成功构建前端和后端。
【讨论】:
以上是关于依赖关系在错误的地方与纱线的主要内容,如果未能解决你的问题,请参考以下文章