bikecoders / ngx-deploy-npm

Nx plugin to publish any JS library to NPM with one command
https://www.npmjs.com/package/ngx-deploy-npm
MIT License
108 stars 13 forks source link

TypeError: Cannot read properties of undefined (reading 'defaultProject') #471

Closed ryanbas21 closed 1 year ago

ryanbas21 commented 1 year ago

its weird, seems when I debug locally the nxJson argument is undefined.

However my version (latest nx) is not officially supported right now by this plugin. 15.6.3.

So i'm going to guess 15.6.3 is the cause of this problem as its not officially supported and i've seen some issues along the lines of getting this plugin in line with the newer nx releases. I created this issue because i had not seen this error itself anywhere.

For what its worth, nx.json does have a defaultProject key in this case. its just an undefined argument in this method of the Workspaces class here which is in Nx itself not this plugin but maybe it helps:

     calculateDefaultProjectName(cwd, projects, nxJson) {
        const relativeCwd = this.relativeCwd(cwd);
        if (relativeCwd) {
            const matchingProject = Object.keys(projects.projects).find((p) => {
                const projectRoot = projects.projects[p].root;
                return (relativeCwd == projectRoot ||
                    relativeCwd.startsWith(`${projectRoot}/`));
            });
            if (matchingProject)
                return matchingProject;
        }
        console.log('json?', nxJson)
        return nxJson.defaultProject;
    }
dianjuar commented 1 year ago

Let me try to understand. You have a project on 15.6.3, and it's failing, right?

ryanbas21 commented 1 year ago

Let me try to understand. You have a project on 15.6.3, and it's failing, right?

This is correct

dianjuar commented 1 year ago

@ryanbas21 I understand. Currently, on #470 we are working to have a solution.

dianjuar commented 1 year ago

@ryanbas21 The potential fix is deployed under ngx-deploy-npm@5.0.0.

Let us know if V5 solves your problem.

dianjuar commented 1 year ago

I need help understanding the problem that you are facing.

Recently we published (v5) to support more comprehensive versions of nx. I initially thought that was your problem, but I wonder if it is.

Can you provide this information to understand your case better:

### Current Behavior
<!-- What is the behavior that currently you experience? -->

### Expected Behavior
<!-- What is the behavior that you expect to happen? -->

### GitHub Repo
<!-- This is extremely important! If this issue is reproduce-able on https://github.com/nrwl/nx-examples, you may use that as the repo.
If not, please do take a few minutes of your time to create a repo to help us reproduce the issue.
This is the best way to help us reproduce the issue and fix it as soon as possible. -->

### Steps to Reproduce
<!-- Please provide some instructions to reproduce the issue in the repo provided above. Be as detailed as possible. -->

1.

### Nx Report
<!-- Please paste the contents shown by nx report. This will be automatically formatted into code, so no need for backticks. -->

### Failure Logs
<!--  Please include any relevant log snippets or files here  -->

### Additional Information
<!-- Is there any additional information that you can provide? -->
jshaw-decides commented 1 year ago

I'm running into this issue as well. I have tried debugging for a bit but looking into other options.

dianjuar commented 1 year ago

@mogulx-operates, can you please fill in the above list to try to reproduce your error?

jshaw-decides commented 1 year ago

@mogulx-operates, can you please fill in the above list to try to reproduce your error?

Meh, moving on. Try to publish a package with the latest version of nx and you'll reproduce the error.

UPDATE: this works if you're just looking to publish javascript packages.

jshaw-decides commented 1 year ago

@mogulx-operates, can you please fill in the above list to try to reproduce your error?

Meh, moving on. Try to publish a package with the latest version of nx and you'll reproduce the error.

  • Node: v16.18.0
  • npx create-nx-workspace@15.7.2 preset-ts --preset=ts
  • npx nx@15.7.2 generate @nrwl/js:library vite-swc --unitTestRunner=vitest --bundler=vite --compiler=swc --directory=web --publishable --importPath=vite-swc
  • npm install --save-dev ngx-deploy-npm
  • nx generate ngx-deploy-npm:install
  • build vite-swc
  • Run publish on vite-swc (assumes there's something to publish)

I lied this works with this configuration. I'll spin up a repo with this working "workspace" and a workspace that repros.

dianjuar commented 1 year ago

We are closing the issue. There needs to be more information to reproduce it.


I assume your current Nx version has a bug with the nrwl/dev-kit (dependency of ngx-deploy-npm). We recently closed an issue due to the same reason