-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
package.json main attribute should be a string #4743
Comments
Same here... |
@sbruno do you know how we could fix this? I'm not an expert in this matter, but if you don't feel like making a PR and you can explain me what to do I'll do it |
@imbalind I'm not an expert either... I think there are a couple of possibilities, but I don't know if they could have any side effect in npm packaging. One option, since the source code already has a package.json could be to save it as is to the distribution package. The plugin.js file I mentioned, creates a new one and adds a version, but the package.json in the source already has a version. Anyway we could keep the code that saves the verision, just instead of using the json object used for generating the bower.json file use the object read from the source package.json. This is done in line 11 of plugins.js: Line 11 in 9d1a0b4
So the change could be something like this:
I think that may work.... Other option could be to overwrite the main attribute of the object that is now being saved to bower.json and package json, choosing the .js file of the array, when saving it to the package.json file. Something like:
This would be implementing the workaround. |
The same contents saved to bower.json were being saved to package.json, generating an invalid package.json since the main attribute was an array instead of a string. Now this has been changed, and the package.json generated for distribution contains the same contents of the package.json file in the source code. Fixes angular-ui#4743
Is there a workaround for this? I do have the same problem. |
+1 I managed to get through this with these lines in the "browser": {
"angular-ui-grid": "./node_modules/angular-ui-grid/ui-grid.js"
} |
In my case, I did a script to modify the contents of the package.json and added it to the build system. // Hack angular-ui-grid until bug gets fixed https://github.com/angular-ui/ui-grid/issues/4743
var fs = require("fs");
var file = "web-app/bower_components/angular-ui-grid/package.json";
var contents = fs.readFileSync(file);
var json = JSON.parse(contents);
json.main = './ui-grid.js';
fs.writeFileSync(file, JSON.stringify(json, null, 4)); |
The same contents saved to bower.json were being saved to package.json, generating an invalid package.json since the main attribute was an array instead of a string. Now this has been changed, and the package.json generated for distribution contains the same contents of the package.json file in the source code. Fixes angular-ui#4743
This broke releasing. |
Would it not be possible to add an require("./less");
require("./ui-grid.css");
require("./ui-grid.eot");
require("./ui-grid.js");
require("./ui-grid.svg");
require("./ui-grid.ttf");
require("./ui-grid.woff");
module.exports = 'ui.grid'; Then in "main": "./index.js", This would be great for me as I am using If those who opened this ticket think that this is a solution that will work for them then I'm happy to make the change and open the PR. |
@Choc13, I use gulp as my build tool and unfortunately your solution didn't work for me. |
For me, using |
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
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:
ui-grid/lib/grunt/plugins.js
Line 336 in 9d1a0b4
The text was updated successfully, but these errors were encountered: