syntax error in none relevant package.json results in npm publish failure #3038

Closed
AndreasMadsen opened this Issue Jan 5, 2013 · 4 comments

Projects

None yet

4 participants

@AndreasMadsen

When I try to publish this module https://github.com/AndreasMadsen/localizer I get the following error:

npm ERR! tar pack Error reading .
npm ERR! TypeError: Cannot call method 'filter' of undefined
npm ERR!     at Packer.IgnoreReader.addIgnoreRules (/Users/Andreas/node/lib/node_modules/npm/node_modules/fstream-npm/node_modules/fstream-ignore/ignore.js:148:13)
npm ERR!     at Packer.IgnoreReader.addIgnoreFile (/Users/Andreas/node/lib/node_modules/npm/node_modules/fstream-npm/node_modules/fstream-ignore/ignore.js:133:10)
npm ERR!     at fs.readFile (fs.js:176:14)
npm ERR!     at fs.close (/Users/Andreas/node/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:90:5)
npm ERR!     at Object.oncomplete (fs.js:297:15)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Darwin 12.2.0
npm ERR! command "/Users/Andreas/node/bin/node" "/Users/Andreas/node/bin/npm" "publish"
npm ERR! cwd /Users/Andreas/Sites/node_modules/localizer
npm ERR! node -v v0.8.15
npm ERR! npm -v 1.1.70
npm ERR! type non_object_property_call
npm ERR! addLocalDirectory Could not pack "." to "/var/folders/__/7q5ydj6n51b6ltjdk00jncl80000gn/T/npm-5014/1357412546410-0.8118197470903397/tmp.tgz"
npm ERR! addLocal Could not install .
npm ERR! SyntaxError: Unexpected token s
npm ERR!     at Object.parse (native)
npm ERR!     at Packer.readRules (/Users/Andreas/node/lib/node_modules/npm/node_modules/fstream-npm/fstream-npm.js:189:33)
npm ERR!     at Packer.IgnoreReader.addIgnoreFile (/Users/Andreas/node/lib/node_modules/npm/node_modules/fstream-npm/node_modules/fstream-ignore/ignore.js:132:22)
npm ERR!     at fs.readFile (fs.js:176:14)
npm ERR!     at fs.close (/Users/Andreas/node/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:90:5)
npm ERR!     at Object.oncomplete (fs.js:297:15)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Darwin 12.2.0
npm ERR! command "/Users/Andreas/node/bin/node" "/Users/Andreas/node/bin/npm" "publish"
npm ERR! cwd /Users/Andreas/Sites/node_modules/localizer
npm ERR! node -v v0.8.15
npm ERR! npm -v 1.1.70
npm ERR! file /Users/Andreas/Sites/node_modules/localizer/test/level/node_modules/faulty/package.json
npm ERR! path /Users/Andreas/Sites/node_modules/localizer/test/level/node_modules/faulty
npm ERR! type unexpected_token
npm ERR! fstream_path /Users/Andreas/Sites/node_modules/localizer/test/level/node_modules/faulty
npm ERR! fstream_type Directory
npm ERR! fstream_class Packer
npm ERR! fstream_stack Packer.readRules (/Users/Andreas/node/lib/node_modules/npm/node_modules/fstream-npm/fstream-npm.js:192:10)
npm ERR! fstream_stack Packer.IgnoreReader.addIgnoreFile (/Users/Andreas/node/lib/node_modules/npm/node_modules/fstream-npm/node_modules/fstream-ignore/ignore.js:132:22)
npm ERR! fstream_stack fs.readFile (fs.js:176:14)
npm ERR! fstream_stack fs.close (/Users/Andreas/node/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:90:5)
npm ERR! fstream_stack Object.oncomplete (fs.js:297:15)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/Andreas/Sites/node_modules/localizer/npm-debug.log
npm ERR! not ok code 0

I'm quite sure it is because of this file https://github.com/AndreasMadsen/localizer/blob/master/test/level/node_modules/faulty/package.json but I don't see any reason for npm to JSON.parse it.

@mfncooper
Member

This is something I've run into before, in a similar situation - that is, trying to include a bogus package.json file for testing purposes. Here's what's going on.

One of the steps of publishing a package is packing it, which is to say, creating the tarball. It's during this step that the problem is showing up. The key thing to know is that, in addition to looking at .npmignore and .gitignore files for what not to pack, npm also looks at the "files" field in package.json to see which files it should include. It does this for every package.json file it finds.

So what's happening here is that npm (actually fstream-npm) is finding your bogus package.json file, reading it, and trying to parse the JSON to look for a "files" entry in there. When the parse fails, readRules() returns undefined, which is then dereferenced, causing the failure you're seeing.

I think there are two separate issues here. One is a trivial-to-fix bug where fstream-npm's readRules() function should be returning an empty array rather than undefined when the JSON parse fails. That addresses the TypeError. The other issue is that it seems to me (but is @isaacs call, obviously) that failing to parse an ignore file shouldn't really be a fatal error. Right now it is treated as such by virtue of fstream's error function being called when the parse fails. If npm simply output a warning message instead, we could let the pack (and publish) continue.

@timoxley
Member
timoxley commented Jan 7, 2014

@AndreasMadsen For invalid package.json's I believe you just need to add '"private": true' in your package.json and/or add the file/folder to your .npmignore

@timoxley
Member
timoxley commented Jan 7, 2014

@AndreasMadsen if you find that this solves your problem can you please close this issue?

@iarna
Member
iarna commented Sep 17, 2014

As we haven't heard anything since, ah, January 2013, I'm going to close this.

@iarna iarna closed this Sep 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment