Skip to content

package.json main attribute should be a string #4743

@sbruno

Description

@sbruno

I'm using ui-grid on a nodejs project and it is failing to do a npm publish because it expects package.json main to be a string and currently it is an array

npm verb stack TypeError: Path must be a string. Received [ './less',
npm verb stack   './ui-grid.css',
npm verb stack   './ui-grid.eot',
npm verb stack   './ui-grid.js',
npm verb stack   './ui-grid.svg',
npm verb stack   './ui-grid.ttf',
npm verb stack   './ui-grid.woff' ]
npm verb stack     at assertPath (path.js:8:11)
npm verb stack     at Object.win32.resolve (path.js:130:5)
npm verb stack     at Packer.applyIgnores (C:\Program Files\nodejs\node_modules\npm\node_modules\fstream-npm\fstream-npm.js:109:59)
npm verb stack     at Packer.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\fstream-npm\node_modules\fstream-ignore\ignore.js:181:17)
npm verb stack     at Array.filter (native)
npm verb stack     at Packer.IgnoreReader.filterEntries (C:\Program Files\nodejs\node_modules\npm\node_modules\fstream-npm\node_modules\fstream-ignore\ignore.js:179:31)
npm verb stack     at Packer.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\fstream-npm\node_modules\fstream-ignore\ignore.js:92:12)
npm verb stack     at Packer.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\fstream-npm\node_modules\fstream-ignore\ignore.js:134:5)
npm verb stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:76:16
npm verb stack     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

On older versions of node it was not failing probably because node is now doing some validation, but according to the docs, an array is not valid and it should be a string:
https://docs.npmjs.com/files/package.json#main

The array was added by this issue: #3673
It looks as some tool extracts information from the main property of bower.json, but it does not say anything about package.json.
Maybe package.json is generated from bower.json, but some special care should be taken for the main attribute.
I see that in the source, package.json and bower.json are different, in fact, package.json does not contain a main attribute. But when I see my module at src\web-app\bower_components\angular-ui-grid\package.json it looks like bower.json

https://github.com/angular-ui/ui-grid/blob/master/bower.json
https://github.com/angular-ui/ui-grid/blob/master/package.json

For example, bootstrap-bower have different values for main in bower.json and package.json:

https://github.com/angular-ui/bootstrap-bower/blob/master/bower.json

https://github.com/angular-ui/bootstrap-bower/blob/master/package.json

Ohh... After inspecting a bit the code, it looks as the problem is in this task, that is copying the same contents to package.json and bower.json:

fs.writeFileSync(pkgJsonFile, JSON.stringify(json, null, 2));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions