Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✖ Cannot read property 'length' of undefined #613

Closed
jakobrosenberg opened this issue May 17, 2021 · 8 comments · Fixed by #625
Closed

✖ Cannot read property 'length' of undefined #613

jakobrosenberg opened this issue May 17, 2021 · 8 comments · Fixed by #625

Comments

@jakobrosenberg
Copy link

jakobrosenberg commented May 17, 2021

np errors on np

np

Warning: No files field specified in package.json nor is a .npmignore file present. Having one of those will prevent you present. Having one of those will prevent you from accidentally publishinackage's source code to npm.g development-specific files along with your package's source code to npm.


✖ Cannot read property 'length' of undefined

Environment

np - can't get version, but fresh install
Node.js - 15.14.0
npm - 7.5.0
Git - 2.24.0.windows.2
OS - Windows 10

Volta - 1.0.2

@jakobrosenberg
Copy link
Author

jakobrosenberg commented May 19, 2021

Works with previous release: 7.4.0.

@dopecodez
Copy link
Collaborator

I cant reproduce this on my windows machine. any other pointers on how to reproduce this would be helpful @jakobrosenberg .

Is this happening for a new repo or for a repo which was already using np?

@jakobrosenberg
Copy link
Author

@dopecodez I honestly can't remember. If I come across the bug error again, I'll let you know.

@michail-peterlis
Copy link

michail-peterlis commented Aug 27, 2021

I have the same issue. It is on an new repo. (I'm first time np user...)
node.js - v14.17.5 / v16.8.0
npm - 7.21.1
git - 2.32.0.windows.2 / 2.33.0.windows.2
np installed today (np -v instantly produces the error)
windows 10
running commands from vscode powershell terminal.

$ np -v

Warning: No files field specified in package.json nor is a .npmignore file present. Having one of those will prevent you from accidentally publishing development-specific files along with your package's source code to npm.

✖ Cannot read property 'length' of undefined

Update

After first running npm publish to create the inital package, np can be used.

@dopecodez
Copy link
Collaborator

I still can't reproduce this even after using all the versions you mentioned in your issue. Do you have a sample repo where you can reproduce this issue?

@reatexpk
Copy link

reatexpk commented Sep 10, 2021

I've also encountered this issue. I'm running on node v14.17.3 and np v7.5.0.
I wrapped the code inside cli-implementation.js into try catch blocks and it threw this error with stacktrace:

Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at checkNewFiles (/Users/reatex/projects/trinity-ui/node_modules/np/source/ui.js:89:27)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async module.exports (/Users/reatex/projects/trinity-ui/node_modules/np/source/ui.js:123:30)
    at async /Users/reatex/projects/trinity-ui/node_modules/np/source/cli-implementation.js:137:19

Further, the object newFiles returned by await util.getNewFiles(pkg) inside checkNewFiles function contains field unpublished which is undefined because I don't have either files field in package.json or .npmignore (obviously, function getNewAndUnpublishedFiles does exactly that checks and returns undefined in this case). It also contains field firstTime with my new files that I want to publish (that's the correct behavior I guess). And then on the line 91 it tries to get the length of that undefined unpublished. Seems like the condition on the line 86 isn't working properly and causes such bugs.
This condition returns false:

(!newFiles.unpublished || newFiles.unpublished.length === 0) && (!newFiles.firstTime || newFiles.firstTime.length === 0)

If this is a real bug and you provide me with the information about what newFiles object was supposed to represent, I can probably make a PR 👉👈

@jakobrosenberg
Copy link
Author

Getting this error again on new library.

  1. npm publish (first release)
  2. make changes, commit and push
  3. npx np --no-tests (✖ Cannot read property 'length' of undefined)

@itaisteinherz
Copy link
Collaborator

itaisteinherz commented Sep 17, 2021

@reatexpk Thanks for the detailed writeup! I was also able to reproduce this by doing the following:

  1. In an existing package of mine, which already has 1 release, remove the files property from package.json.
  2. Commit the change (doesn't matter if you push the commit or not).
  3. Run $ np.
  4. You should now be getting this output:
❯ np


Warning: No files field specified in package.json nor is a .npmignore file present. Having one of those will prevent you from accidentally publishing development-specific files along with your package's source code to npm.


✖ Cannot read property 'length' of undefined

Will try to get a fix together later today :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants