我在NX monorepo中有一个项目(杂货店)使用了nestjs。这个应用程序是一个严格的后端API。我想添加一个前端,为此我将react拖到了这个项目中。在monorepo中生成了一个新项目(nx g @nrwl/react:app grocery-shop-webapp
)后-我无法运行任何一个(nx serve grocery-shop
)。
我收到一条错误消息:
NX无法读取未定义的属性(阅读“projects”)
我的nx.json文件代码如下所示:
{
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"npmScope": "grocery-shop",
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/nx-cloud",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"],
"accessToken": "NjYzNzg4YjMtYjM1ZC00M2NkLThhNzAtZWE2NzM4ZjhiNWUzfHJlYWQtd3JpdGU="
}
}
},
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"inputs": ["production", "^production"]
},
"test": {
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"]
},
"lint": {
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"]
},
"e2e": {
"inputs": ["default", "^production"]
}
},
"namedInputs": {
"default": ["{projectRoot}/**/*", "sharedGlobals"],
"production": [
"default",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/.eslintrc.json"
],
"sharedGlobals": ["{workspaceRoot}/babel.config.json"]
},
"defaultProject": "grocery-shop",
"generators": {
"@nrwl/react": {
"application": {
"style": "css",
"linter": "eslint",
"bundler": "webpack",
"babel": true
},
"component": {
"style": "css"
},
"library": {
"style": "css",
"linter": "eslint"
}
}
}
}
所以我决定在这个文件中手动实现“projects”选项。
...
"npmScope": "grocery-shop",
"projects": {
"grocery-shop": {
"root": "apps/grocery-shop",
"tags": []
},
"grocery-shop-webapp": {
"root": "apps/grocery-shop-webapp",
"tags": []
}
}
...
所以现在当我尝试运行nx serve grocery-shop
时,我得到一条错误消息:
NX自Nx 13起,项目配置应从nx.json移至workspace. json/project.json。请运行“nx format”来修复此问题。
NX找不到任务杂货店的配置:服务
我会提到“nx format
“并没有改善任何东西,错误仍然存在。
你们能帮我运行两个应用程序吗?
编辑:nx report
输出:
npm : 9.2.0
nx : 15.3.3
@nrwl/angular : Not Found
@nrwl/cypress : 15.6.2
@nrwl/detox : Not Found
@nrwl/devkit : 15.3.3
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : 15.3.3
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 15.6.2
@nrwl/js : 15.6.2
@nrwl/linter : 15.3.3
@nrwl/nest : 15.4.2
@nrwl/next : Not Found
@nrwl/node : 15.3.3
@nrwl/nx-cloud : 15.0.2
@nrwl/nx-plugin : Not Found
@nrwl/react : 15.6.2
@nrwl/react-native : Not Found
@nrwl/rollup : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : Not Found
@nrwl/webpack : 15.3.3
@nrwl/workspace : 15.3.3
typescript : 4.9.4
解决方案:正如@Craigory Coppola正确指出的那样,我使用nx migrate latest
命令更新了NX的版本及其依赖项--我的依赖项版本不匹配。
1条答案
按热度按时间jvlzgdj91#
看起来你可能有不匹配的nrwl/nx包版本,你能运行
nx report
吗?除了nx cloud之外,它们应该都相同