add-nx's People
Forkers
mandarini gustavobini agentender basixkor frozenpandaz leosvelperez neutrico william3johnson inferno-incadd-nx's Issues
NX cannot locate projects/packages without a scaffolded workspace.json file
Summary
NX is not able to locate project/packages in a monorepo to which it was added (via this add-nx-to-monorepo
generator).
Details
The add-nx-to-monorepo
recently removed the scaffolding of the workspace.json
, however the latest nx
CLI doesn't (yet) seem to be able to recognize nested packages/projects without that file.
The workspace.json
did make it so that project names can be mapped to folder locations in a monorepo, however this is likely consolidated now into the nx.json
.
My expectation was the nx
CLI was modified so that it would be able to recognize projects without that explicit mapping (probably traversing folders and searching for nested package.json
and/or project.json
files?). However the latest version of nx
doesn't seem to be able to locate projects without it.
I did update to the latest of nx
(via yarn global upgrade
) and confirmed afterwards it's the latest via npm view nx
.
Steps to Reproduce
To reproduce easily, here is a public, open-source repository I've been migrating from Lerna to NX (feel free to clone and use):
I'll outline the steps I took and hopefully will make it easier for you to assist or give me any homework.
- Removed the
package-lock.json
andnode_modules/
-rm -rf node_modules package-lock.json
- Switched to
yarn
and create the lock file-yarn install
- Add NX to the repo -
npx add-nx-to-monorepo
- Added the new JS/TS generator -
yarn add --dev @nrwl/js
- Create a new (buildable) TS package -
yarn nx g @nrwl/js:lib scalars --buildable
- Run (any) NX command on that package/project -
nx test scalars
ornx build scalars
Could not find project "scalars"
Questions
I'm not sure if there is an issue with this generator or with NX or rather if there's a mistake I'm making which you can help point out. Maybe I even need to open/move this issue to another repo. Regardless, I'm happy to assist or create a PR if you can point me in the right direction.
These are my (speculation) questions:
- Is there supposed to be something different written explicitly to the
nx.json
now to replace the project mapping previously located in theworkspace.json
? If so, is it possible this generator just needs to be updated to do it too? - Is there supposed to be a change coming to the
nx
CLI to accommodate the deprecation of theworkspace.json
?
NX version: 13.4.1
Yarn version: 1.22.0
Node version: v14.17.0
OS version: Fedora v35
fails if the repo is already under version control with no .gitignore
Originally spotted by @trumbitta, transfered here to keep things organized!
Fails running with yarn 2
Hi :-)
I just tried to run yarn dlx add-nx-to-monorepo
and got the following error:
Error: add-nx-to-monorepo tried to access tslib, but it isn't declared in its dependencies;
this makes the require call ambiguous and unsound.
I'm using yarn v3.0.2
Full output:
/private/var/folders/4y/blwdwqdx3j19xg3crjw608s80000gp/T/xfs-998e284c/dlx-5866/.pnp.cjs:11760
throw firstError;
^
Error: add-nx-to-monorepo tried to access tslib, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
Required package: tslib
Required by: add-nx-to-monorepo@npm:1.4.1 (via /Users/ben1/.yarn/berry/cache/add-nx-to-monorepo-npm-1.4.1-9a8f29eea3-8.zip/node_modules/add-nx-to-monorepo/src/)
Require stack:
- /Users/ben1/.yarn/berry/cache/add-nx-to-monorepo-npm-1.4.1-9a8f29eea3-8.zip/node_modules/add-nx-to-monorepo/src/add-nx-to-monorepo.js
at Function.external_module_.Module._resolveFilename (/private/var/folders/4y/blwdwqdx3j19xg3crjw608s80000gp/T/xfs-998e284c/dlx-5866/.pnp.cjs:11759:55)
at Function.external_module_.Module._load (/private/var/folders/4y/blwdwqdx3j19xg3crjw608s80000gp/T/xfs-998e284c/dlx-5866/.pnp.cjs:11558:48)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/Users/ben1/.yarn/berry/cache/add-nx-to-monorepo-npm-1.4.1-9a8f29eea3-8.zip/node_modules/add-nx-to-monorepo/src/add-nx-to-monorepo.js:5:17)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.external_module_.Module._load (/private/var/folders/4y/blwdwqdx3j19xg3crjw608s80000gp/T/xfs-998e284c/dlx-5866/.pnp.cjs:11608:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
if package.json name contains _ it does not work
package.json
{
"name": "asdf_test"
...
}
this does not work. npx cra-to-nx
gives this error
ENOENT: no such file or directory, stat 'temp-workspace/apps/asdf_test/project.json'
but creates this folder temp-workspace/apps/asdf-test/
WORKAROUND
change package.json name _
to -
Wrong package manager used to build package
Hi,
In make-angular-cli-faster.ts in most cases you check if yarn or npm is used in project but on the end to install all deps you run npm install regardless of used package manager. It will be nice to stick to proper manager.
No valid versions available for temp-workspace when trying cra-to-nx
I get this error when running npx cra-to-nx
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'install',
1 verbose cli 'temp-workspace@latest',
1 verbose cli '--global',
1 verbose cli '--prefix',
1 verbose cli 'C:\Users\xxxxx\AppData\Roaming\npm-cache\_npx\239200',
1 verbose cli '--loglevel',
1 verbose cli 'error',
1 verbose cli '--json'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 0d3519544f2ec742
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 304 https://registry.npmjs.org/temp-workspace 872ms (from cache)
8 silly fetchPackageMetaData error for temp-workspace@latest No valid versions available for temp-workspace
9 timing stage:rollbackFailedOptional Completed in 1ms
10 timing stage:runTopLevelLifecycles Completed in 895ms
11 verbose type tag
12 verbose stack temp-workspace: No valid versions available for temp-workspace
12 verbose stack at pickManifest (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-pick-manifest\index.js:39:11)
12 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\manifest.js:24:14
12 verbose stack at tryCatcher (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
12 verbose stack at Promise._settlePromiseFromHandler (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:517:31)
12 verbose stack at Promise._settlePromise (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:574:18)
12 verbose stack at Promise._settlePromise0 (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:619:10)
12 verbose stack at Promise._settlePromises (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:699:18)
12 verbose stack at _drainQueueStep (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:138:12)
12 verbose stack at _drainQueue (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:131:9)
12 verbose stack at Async._drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:147:5)
12 verbose stack at Immediate.Async.drainQueues [as _onImmediate] (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:17:14)
12 verbose stack at processImmediate (internal/timers.js:464:21)
13 verbose cwd C:\Dev\NX\nx-monorepo\track-my-appeal
14 verbose Windows_NT 10.0.19042
15 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "temp-workspace@latest" "--global" "--prefix" "C:\Users\xxxx\AppData\Roaming\npm-cache\_npx\239200" "--loglevel" "error" "--json"
16 verbose node v14.18.1
17 verbose npm v6.14.15
18 error code ENOVERSIONS
19 error No valid versions available for temp-workspace
20 verbose exit [ 1, true ]
Migration of yarn workspace - no cache config for targets in package.json
Hi,
I've got a yarn workspace that I've migrated and it appears to work fine until we get to the stage of things getting cached.
As far as I can find from a blog article introducing Nx caching, it appears that dist is the default folder, but there is no documentation on:
- how Nx knows to refer to package.json rather than command targets in nx.json and workspace.json or a combination of them
- what plugin is responsible for delegating to package.json and how to override paths
- why things are built in the wrong order using both --all and --with-deps
cra-to-nx attempts to edit project.json, but does not create it
I've been attempting migrate a create-react-app project to Nx by running npx cra-to-nx
, and everything appears to work until the script tries to add the CRA commands to workspace.json, at which point it throws this error:
ENOENT: no such file or directory, open '/Users/KevinYaroch/amount-repos/nx-test-app/temp-workspace/apps/nx-test-app/project.json'
Error: Command failed: npx nx g @nrwl/workspace:run-commands serve --project nx-test-app --command "node ../../node_modules/.bin/react-app-rewired start" --cwd "apps/nx-test-app"
at checkExecSyncError (child_process.js:643:11)
at Object.execSync (child_process.js:679:15)
at Object.addCRACommandsToWorkspaceJson (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/src/lib/add-cra-commands-to-nx.js:6:21)
at Object.<anonymous> (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/src/lib/cra-to-nx.js:58:34)
at Generator.next (<anonymous>)
at /Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/node_modules/tslib/tslib.js:117:75
at new Promise (<anonymous>)
at Object.__awaiter (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/node_modules/tslib/tslib.js:113:16)
at Object.createNxWorkspaceForReact (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/src/lib/cra-to-nx.js:36:20)
at Object.<anonymous> (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/src/index.js:7:13)
I was able to replicate this with a newly created CRA app with the default settings, so I don't think anything in my existing app is causing this.
It looks like using project.json
is the default in Nx 13, so I'm guessing that some of the commands called by cra-to-nx are using the Nx 12 behavior and some are using Nx 13?
[ETA: I should clarify that when I copied the backtrace above, I was using a local yarn install of cra-to-nx, but the result is the same if I run it using npx.]
add-nx-to-monorepo broken with Nx 13.9.x
Nx 13.9.x introduced a change in the required dependencies in package.json: "nx": "latest"
was added and @nrwl/cli
and @nrwl/tao
was removed.
The add-nx-to-monorepo
command is not updated to reflect that.
This issue came out when trying to figure out the root cause for:
nrwl/nx#9359
can't use on node 12 project
node 12 project
...
> NX ๐ Please be patient, one final step remaining!
> NX ๐งถ Adding npm packages to your new Nx workspace to support CRA
> NX ๐ฆ Adding dependency: react-scripts
yarn add v1.22.17
[1/4] ๐ Resolving packages...
[2/4] ๐ Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version ">=14.0.0". Got "12.22.1"
if I change to node 14
npx: installed 243 in 61.398s
> NX ๐ณ Nx initialization
npm ERR! code ENOVERSIONS
npm ERR! No valid versions available for temp-workspace
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/matar/.npm/_logs/2022-01-28T07_03_03_496Z-debug.log
Install for [ 'temp-workspace@latest' ] failed with code 1
Error: Command failed: npx -y create-nx-workspace@latest temp-workspace --appName=salescircle-front --preset=react --style=css --nx-cloud --packageManager=yarn
at checkExecSyncError (child_process.js:790:11)
at Object.execSync (child_process.js:863:15)
doesn't work with yarn 2 , can not find nx command.
the cli was installed using npm (npm install -g nx), but nx module can't be found inside the project folder and still doesn't work even after i run another yarn install.
NX ERROR Could not find Nx modules in this workspace.
Have you run npm/yarn install?
[add-nx-to-monorepo] As of Nx 13, project configuration should be moved from nx.json to workspace.json/project.json
What happens?
I run npx add-nx-to-monorepo
command on exist yarn workspace project with nx cloud initialization option. And this error happened as below
yarn run v1.22.11
$ /Users/ryanwillpower/codes/monorepo/node_modules/.bin/nx g @nrwl/nx-cloud:init
ERROR As of Nx 13, project configuration should be moved from nx.json to workspace.json/project.json. Please run "nx format" to fix this.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Command failed: yarn nx g @nrwl/nx-cloud:init
at checkExecSyncError (child_process.js:635:11)
at Object.execSync (child_process.js:671:15)
at initCloud (/Users/ryanwillpower/.npm/_npx/69752/lib/node_modules/add-nx-to-monorepo/src/add-nx-to-monorepo.js:286:21)
at /Users/ryanwillpower/.npm/_npx/69752/lib/node_modules/add-nx-to-monorepo/src/add-nx-to-monorepo.js:40:13
at Generator.next (<anonymous>)
at fulfilled (/Users/ryanwillpower/.npm/_npx/69752/lib/node_modules/add-nx-to-monorepo/node_modules/tslib/tslib.js:114:62)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
status: 1,
signal: null,
output: [ null, null, null ],
pid: 69806,
stdout: null,
stderr: null
}
If I don't select nx cloud initialization option, when I run yarn nx run-many --target=build --all --parallel
command, which the terminal suggests to me, the error still happened
โฏ yarn nx run-many --target=build --all --parallel
yarn run v1.22.11
$ /Users/ryanwillpower/codes/monorepo/node_modules/.bin/nx run-many --target=build --all --parallel
ERROR As of Nx 13, project configuration should be moved from nx.json to workspace.json/project.json. Please run "nx format" to fix this.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
What I expected
I expected to run the command npx add-nx-to-monorepo
and after that, I want to run any command without running nx format
to fix this issue.
cra-to-nx: allow to keep git history
It would be really nice to have the possibility to keep the git history while migrating CRA to nx (using git mv
instead of mv
command for instance).
Top level package.json is ignored
The project that I am working on is a npm project that we want to migrate to NX monorepo. When the add-nx-to-monorepo command is run, the error Cannot find any projects in this monorepo
occurs. The project has a package.json file at project root.
This function scan for any package.json file and add NX config files to workspace. However the line mentioned above filters out the package.json at root instead of returning a list of paths containing it.
npx cra-to-nx setup bug
By running npx cra-to-nx on stock CRA I get
The syntax of the command is incorrect.
Error: Command failed: mkdir -p tools/scripts
at Object.addPostinstallPatch (C:\Users\AppData\Local\npm-cache\_npx\2fef4a1ad32917df\node_modules\cra-to-nx\src\lib\add-postinstall-patch.js:7:21)
fails with pnpm, attempts to add devDependencies
under an existing pnpm monorepo attempting to install with described devDependencies throws an error.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.