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

Fails when running if a package.json is missing "name" (Discord.JS) #1200

Closed
lakeshadow0 opened this issue Mar 30, 2019 · 10 comments
Closed
Labels
external issue The root cause is with an external component that needs a fix or workaround

Comments

@lakeshadow0
Copy link

lakeshadow0 commented Mar 30, 2019

When running api-extractor with the following configuration

{
    "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/api-extractor.schema.json",
    "compiler": {
        "configType": "tsconfig",
        "rootFolder": "."
    },
    "project": {
        "entryPointSourceFile": "build/src/index.d.ts"
    }
}

where a package.json exists without a name, the extractor fails. This happens specifically with the Discord.JS package.

$api-extractor run

api-extractor 6.3.0  - http://aka.ms/extractor

Using configuration from *...\api-extractor.json


Error: Error reading "...\node_modules\discord.js\typings\package.json":
  The required field "name" was not found

where the package.json's contents are

{
  "devDependencies": {
    "tslint": "^3.15.1",
    "tslint-config-typings": "^0.2.4",
    "typescript": "^2.2.1"
  },
  "scripts": {
    "lint": "tslint index.d.ts discord.js-test.ts"
  },
  "dependencies": {
    "@types/node": "^7.0.0"
  }
}

To get around this temporarily, I simply added a name. This then caused an error to be thrown for missing version as well.

@octogonz
Copy link
Collaborator

The version field is now optional in API Extractor 7, because even though this violates the NPM spec, it is apparently technically permitted by NodeJS. The name field is absolutely required as far as I know, so if Discord is omitting it, then Discord has a bug.

@octogonz
Copy link
Collaborator

octogonz commented Apr 3, 2019

I'm closing this because (1) the missing version field is fixed in AE7 and (2) the missing name field seems like an external issue with Discord.JS.

Please feel free to reopen the issue if you have further comments/concerns. Thanks!

@octogonz octogonz added the external issue The root cause is with an external component that needs a fix or workaround label Apr 3, 2019
@octogonz octogonz closed this as completed Apr 3, 2019
@avocadowastaken
Copy link

@octogonz Some modules use intermediate package.json files that used by bundlers to enhance tree shaking https://unpkg.com/browse/@material-ui/core@4.3.1/AppBar/package.json.

In that case, there will be no version or name property.

I dived into the code and found that parsing of package.json required only to parse tsdocMetadata, and only a few fields needed for it (tsdocMetadata, typings, types and main) https://github.com/microsoft/web-build-tools/blob/master/apps/api-extractor/src/analyzer/PackageMetadataManager.ts#L74-L104.

Maybe it's worth to update package.json identification policy?

@Pymossy
Copy link

Pymossy commented Dec 23, 2019

Hi,
Does anybody suggest a workaround?
Thank you

@octogonz
Copy link
Collaborator

Make a valid package.json?

@Pymossy
Copy link

Pymossy commented Dec 23, 2019

I think it is better to ignore invalid package.json in subfolders

@octogonz
Copy link
Collaborator

Are you able to share a repro of your problem? If so, please open a new GitHub issue and I can investigate it.

@gregjoeval
Copy link

Was there a solution or separate issue opened to handle the invalid package.json files? (specifically for material-ui)

@octogonz
Copy link
Collaborator

octogonz commented Aug 3, 2020

@gregjoeval My opinion is:

Make a valid package.json

If that isn't possible for some reason, then:

Are you able to share a repro of your problem? If so, please open a new GitHub issue and I can investigate it.

@gregjoeval
Copy link

Here is the new issue: #2070

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external issue The root cause is with an external component that needs a fix or workaround
Projects
None yet
Development

No branches or pull requests

5 participants