Open jaqua opened 1 year ago
Happened with the redlock package for me. Adding import 'redlock';
didn't solve the problem, so I had to create a package.json for the projet using the package.
Using nx 16.10.0
I can confirm this happens with NX 17.0.1 and I'm using ` "executor": "@nx/esbuild:esbuild",
It did work nx@npm:16.6.0
edit: it works with stock npm but NOT working with yarn@4.0.1
PNP
It happened to me too.
Node : 20.8.0
OS : darwin-arm64
yarn : 4.0.2
nx : 17.2.8
@nx/js : 17.2.8
@nx/eslint : 17.2.8
@nx/workspace : 17.2.8
@nx/devkit : 17.2.8
@nx/eslint-plugin : 17.2.8
@nx/plugin : 17.2.8
@nx/react : 17.2.8
@nx/webpack : 17.2.8
typescript : 5.2.2
---------------------------------------
Community plugins:
@ngrx/effects : 17.0.1
@ngrx/store : 17.0.1
---------------------------------------
Local workspace plugins:
nx-customs
I had to fix it quickly so I patched the nx
package:
diff --git a/src/plugins/js/package-json/create-package-json.js b/src/plugins/js/package-json/create-package-json.js
index 374e05e6baa2673c8e56ee71e43fba06348c875b..e8402c30d93fcfb95ed8e5c7201dea65d4afc6b8 100644
--- a/src/plugins/js/package-json/create-package-json.js
+++ b/src/plugins/js/package-json/create-package-json.js
@@ -143,8 +143,38 @@ function findAllNpmDeps(projectFileMap, projectNode, graph, npmDeps, seen, ignor
const projectFiles = (0, task_hasher_1.filterUsingGlobPatterns)(projectNode.data.root, projectFileMap[projectNode.name] || [], rootPatterns ?? dependencyPatterns);
const projectDependencies = new Set();
projectFiles.forEach((fileData) => fileData.deps?.forEach((dep) => projectDependencies.add((0, project_graph_1.fileDataDepTarget)(dep))));
+
+ /**
+ * Issue is related to Yarn 4.0.2 and Nx. Because of that nx:webpack
+ * cannot properly generate package.json with required dependencies.
+ * It's a "dirty hack" to somehow find dependencies in project.
+ * @see https://github.com/nrwl/nx/issues/19226
+ * @see https://github.com/nrwl/nx/issues/20928
+ */
+ const externalNodesKeys = Object.keys(graph.externalNodes);
+ const findNode = (dep) => {
+ if (!dep.startsWith('npm:')) {
+ return undefined
+ }
+
+ const foundKeyRealName = externalNodesKeys.find(k => k.slice(0, k.lastIndexOf('@')) === dep);
+ if (foundKeyRealName) {
+ return graph.externalNodes[foundKeyRealName]
+ }
+
+ const foundKeySimilarName = externalNodesKeys.find(k => k.includes(dep))
+ if (foundKeySimilarName) {
+ return graph.externalNodes[foundKeySimilarName]
+ }
+
+ if (dep.includes('/')) {
+ return findNode(dep.slice(0, dep.lastIndexOf('/')))
+ }
+ return undefined
+ };
+
for (const dep of projectDependencies) {
- const node = graph.externalNodes[dep];
+ const node = findNode(dep);
if (seen.has(dep)) {
// if it's in peerDependencies, move it to regular dependencies
// since this is a direct dependency of the project
I am not sure if the fix will work for everyone but I hope it'll help anyone using Yarn Berry instead of npm.
NX Version: 19.3.0
We are having the same issue, and it's with redlock package as well.
packages/server/api/src/app/helper/lock.ts
Edit: was able to fix after deleting node_modules and package-lock.json then ran npm install from scratch
Current Behavior
Using this file in a nestJS application
upload.resolver.ts
should result in a generated package.json file like this - which worked in v16.1. as expected.
After upgrading to 16.7.2 the
graphql-upload
is missing:If I add
import "graphql-upload"
to the file, the dependency gets added to the generated package.json file.By the way: The latest version (16.8.1.) creates package.json files with empty dependencies. Is there any change of usage, which I didn't find in the docs?
Expected Behavior
Should generate package.json file with all needed dependencies.
GitHub Repo
No response
Steps to Reproduce
1.
Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response